Java Programming OOP Questions and Answers Set 3

Java Programming OOPs

Questions 21 to 30



21.
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.
22.
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.
23.
You read the following statement in a Java program that compiles and executes.
                                  submarine.dive(depth);
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.
24.
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.
25.
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.
26.
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.
27.
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?
28.
What is the output of the following code:
                   class eq
                   {
                      public static void main(String args[])
                      {
                         String s1 = “Hello”;
                         String s2 = new String(s1);
                         System.out.println(s1==s2);
                      }  
                    }
(a)  true                   (b)  false                 (c)  0                       (d)  1                       (e)  Hello.
29.
All exception types are subclasses of the built-in class
(a)  Exception          (b)  RuntimeException                            (c)  Error
(d)  Throwable         (e)  None of the above.
30.
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.

Answers


21.
Answer : (a)
Reason:  Java compiler compiles the source code file and converts it into a class file, which consists of byte code.
22.
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.
23.
Answer : (b)
Reason:  The other choices can be allowed, but not ‘must’
24.
Answer : (b)
Reason:  ‘finalize()’ method is automatically called by the java compiler before destroying the object to free any resources.
25.
Answer : (a)
Reason:  First the package name is defined. Then the import statements if any. And then the class declaration goes on.
26.
Answer : (d)
Reason:  Even though the return type varies, it will not be considered for overloading concept. Only method name and parameters are considered.
27.
Answer : (c)
Reason:  A protected member cannot be accessed in non-subclasses of different packages.
28.
Answer : (b)
Reason:  Since , the contents of the two String objects are identical, but they are distinct objects.
29.
Answer : (d)
Reason:  Throwable is the super class of all the exception classes.
30.
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 >>


11 comments :

  1. This comment has been removed by the author.

    ReplyDelete
  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 http://www.maxmunus.com/contact
    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
    MaxMunus
    E-mail: saurabh@maxmunus.com
    Skype id: saurabhmaxmunus
    Ph:+91 8553576305 / 080 - 41103383
    http://www.maxmunus.com/


    ReplyDelete
  3. Great post! you explore this topic in very effective way I want to appreciate your work, thank you for sharing such a useful information. Artificial Intelligence Course in Muscat | Robotic And Coding For Kids in Muscat | Digital Marketing Training in Muscat | SEO Services in Muscat

    ReplyDelete



  4. very nice blogs!!! i have to learning for lot of information for this sites.Sharing for wonderful information. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing

    Commutative Property of Addition
    Vertical Angles
    Lesson on Greater than Sign
    edublack boards

    ReplyDelete
  5. Hi, Thank you for this informative blog, I have just started to learn java course and this blog is really informative for me. Thank you for this blog!

    ReplyDelete
  6. Thank you for sharing this amazing post. Looking forward to reading more.
    Visit us: Java Training
    Visit us: Java Course

    ReplyDelete