Sail E0 Webinar

MCQs

Total Questions : 10
Question 1. Which of the following is not a marker interface?
  1.    Serializable
  2.    Cloneable
  3.    Remote
  4.    Reader
 Discuss Question
Answer: Option D. -> Reader




Question 2.

Given code snippet

class ReflectionDemo{      

   public static void main(String... str){      

        try {  

            Class cls = Class.forName("java.lang.String[]");  

            System.out.print(cls.getClass());  

        } catch (ClassNotFoundException ex) {  

            System.out.print("Exception Occured");  

        }  

   }  

}  

What is the output?

  1.    Compile Time Error
  2.    Prints [Ljava.lang.String; on console
  3.    Prints [Ljava.lang.String; Exception Occured on console
  4.    Prints Exception Occur on console
 Discuss Question
Answer: Option D. -> Prints Exception Occur on console




Question 3. How to get the class object of associated class using Reflection?
  1.    Class.forName(className")
  2.    Class.name(className")
  3.    className.getClass()
  4.    className.getClassName()
 Discuss Question
Answer: Option B. -> Class.name(className")




Question 4. What does foo.getClass().getMethod("doSomething, null) return?
  1.    doSomething method instance
  2.    Method is returned and we can call the method as method.invoke(foo,null);
  3.    Class object
  4.    Exception is thrown
 Discuss Question
Answer: Option B. -> Method is returned and we can call the method as method.invoke(foo,null);




Question 5. How private method will be called using reflection?
  1.    getDeclaredFields
  2.    getDeclaredMethods
  3.    getMethods
  4.    getFields
 Discuss Question
Answer: Option B. -> getDeclaredMethods




Question 6. What does Class.forName("myreflection.Foo).getInstance() return?
  1.    An array of Foo objects
  2.    class object of Foo
  3.    Calls the getInstance() method of Foo class
  4.    Foo object
 Discuss Question
Answer: Option D. -> Foo object




Question 7. How method is to be invoked on Unknown object?
  1.    obj.getClass().getDeclaredMethod()
  2.    obj.getClass().getDeclaredField()
  3.    obj.getClass().getMethod()
  4.    obj.getClass().getObject()
 Discuss Question
Answer: Option C. -> obj.getClass().getMethod()




Question 8. What are the drawbacks of Java Reflection?
  1.    Performance Overhead
  2.    Exposure of Internals
  3.    Both A and B
  4.    None
 Discuss Question
Answer: Option C. -> Both A and B




Question 9. What are the advantages of using reflection?
  1.    Extensibility Features
  2.    Debugging and testing tools
  3.    Both A and B
  4.    None of these
 Discuss Question
Answer: Option C. -> Both A and B




Question 10. What is not the advantage of Reflection?
  1.    Examine a class's field and method at runtime
  2.    Construct an object for a class at runtime
  3.    Examine a class's field at compile time
  4.    Examine an object's class at runtime
 Discuss Question
Answer: Option C. -> Examine a class's field at compile time




Latest Videos

Latest Test Papers