Java Programming OOP Questions and Answers Set 3

Java Programming OOPs

Questions 21 to 30

What is byte code in the context of Java?
(a)   The type of code generated by a Java compiler.
(b)   The type of code generated by a Java Virtual Machine.
(c)   It is another name for a Java source file.
(d)   It is the code written within the instance methods of a class.
(e)   It is another name for comments written within a program.
What is garbage collection in the context of Java?
(a)   The operating system periodically deletes all the java files available on the system.
(b)   Any package imported in a program and not used is automatically deleted.
(c)   When all references to an object are gone, the memory used by the object is automatically reclaimed.
(d)   The JVM checks the output of any Java program and deletes anything that doesn't make sense.
(e)   Janitors working for Sun Micro Systems are required to throw away any Microsoft documentation found in the employees' offices.
You read the following statement in a Java program that compiles and executes.
What can you say for sure?
(a)   depth must be an int
(b)   dive must be a method.
(c)   dive must be the name of an instance field.
(d)   submarine must be the name of a class
(e)   submarine must be a method.
The java run time system automatically calls this method while garbage collection.
(a)  finalizer()                                          (b)  finalize()                                          (c)  finally()
(d)  finalized()                                        (e)  none of the above.
The correct order of the declarations in a Java program is,
(a)   Package declaration,  import statement, class declaration
(b)   Import statement, package declaration, class declaration
(c)   Import statement, class declaration, package declaration
(d)   Class declaration, import statement, package declaration
(e)   Class declaration, package declaration, import statement.
An overloaded method consists of,
(a)   The same method name with different types of parameters
(b)   The same method name with different number of parameters
(c)   The same method name and same number and type of parameters with different return type
(d)   Both (a) and (b) above
(e)   (a), (b) and (c) above.
A protected member can be accessed in,
(a)  a subclass of the same package      (b)  a non-subclass of the same package
(c)  a non-subclass of different package (d)  a subclass of different package
(e)  the same class.
Which is the false option?
What is the output of the following code:
                   class eq
                      public static void main(String args[])
                         String s1 = “Hello”;
                         String s2 = new String(s1);
(a)  true                   (b)  false                 (c)  0                       (d)  1                       (e)  Hello.
All exception types are subclasses of the built-in class
(a)  Exception          (b)  RuntimeException                            (c)  Error
(d)  Throwable         (e)  None of the above.
When an overridden method is called from within a subclass, it will always  refer to the version of that method defined by the
(a)   Super class
(b)   Subclass
(c)   Compiler will choose randomly  
(d)   Interpreter will choose randomly
(e)   None of the abvove.


Answer : (a)
Reason:  Java compiler compiles the source code file and converts it into a class file, which consists of byte code.
Answer : (c)
Reason:  Garbage collection in the context of Java is when all references to an object are gone, the memory used by the object is automatically reclaimed.
Answer : (b)
Reason:  The other choices can be allowed, but not ‘must’
Answer : (b)
Reason:  ‘finalize()’ method is automatically called by the java compiler before destroying the object to free any resources.
Answer : (a)
Reason:  First the package name is defined. Then the import statements if any. And then the class declaration goes on.
Answer : (d)
Reason:  Even though the return type varies, it will not be considered for overloading concept. Only method name and parameters are considered.
Answer : (c)
Reason:  A protected member cannot be accessed in non-subclasses of different packages.
Answer : (b)
Reason:  Since , the contents of the two String objects are identical, but they are distinct objects.
Answer : (d)
Reason:  Throwable is the super class of all the exception classes.
Answer : (b)
Reason:  The compiler will always selects the version of the method in subclass. superclass method can be called by explicitly assigning super reference.

<< Prev   1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22  

 23   24   25   26   27   28   29   30  Next >>


  1. This comment has been removed by the author.

  2. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in LIFERAY, kindly contact us
    MaxMunus Offer World Class Virtual Instructor led training on LIFERAY. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Saurabh Srivastava
    Skype id: saurabhmaxmunus
    Ph:+91 8553576305 / 080 - 41103383

  3. Thanks for sharing this unique information with us. Your post is really awesome. Your blog is really helpful for me..
    organic oil
    organic oil in jaipur
    organic cold pressed oils
    ayurvedic oil store in jaipur