UNIT-II
INHERITANCE
Questions
1. What is inheritance in Java?
a) Process of creating a new class from an existing class
b) Process of creating a new object from an existing object
c) Process of creating a new method from an existing method
d) Process of creating a new variable from an existing variable
Answer: a) Process of creating a new class from an existing class
2. Which keyword is used to inherit a class in Java?
a) extends
b) implements
c) inherits
d) creates
Answer: a) extends
3. What is the purpose of inheritance in Java?
a) To reduce code duplication
b) To increase code complexity
c) To decrease code readability
d) To increase code length
Answer: a) To reduce code duplication
4. What are the types of inheritance in Java?
a) Single, Multilevel, Hierarchical, and Hybrid
b) Single, Multilevel, and Hierarchical
c) Single, and Multilevel
d) Single, and Hierarchical
Answer: a) Single, Multilevel, Hierarchical, and Hybrid
5. What is single inheritance in Java?
a) A child class inherits from multiple parent classes
b) A child class inherits from a single parent class
c) A parent class inherits from a child class
d) A child class does not inherit from any parent class
Answer: b) A child class inherits from a single parent class
6. What is multilevel inheritance in Java?
a) A child class inherits from a parent class, and the parent class inherits from another
parent class
b) A child class inherits from multiple parent classes
c) A parent class inherits from a child class
d) A child class does not inherit from any parent class
Answer: a) A child class inherits from a parent class, and the parent class inherits from
another parent class
7. What is hierarchical inheritance in Java?
a) A parent class is inherited by multiple child classes
b) A child class inherits from multiple parent classes
c) A parent class inherits from a child class
d) A child class does not inherit from any parent class
Answer: a) A parent class is inherited by multiple child classes
8. What is hybrid inheritance in Java?
a) Combination of single, multilevel, and hierarchical inheritance
b) Combination of single and multilevel inheritance
c) Combination of single and hierarchical inheritance
d) Combination of multilevel and hierarchical inheritance
Answer: a) Combination of single, multilevel, and hierarchical inheritance
9. Can a child class inherit the private members of its parent class?
a) Yes
b) No
Answer: b) No
10. Can a child class override the final methods of its parent class?
a) Yes
b) No
Answer: b) No
11. What is method overriding in Java?
a) When a child class provides a di erent implementation of a method already defined in
its parent class
b) When a child class provides the same implementation of a method already defined in its
parent class
c) When a parent class provides a di erent implementation of a method already defined in
its child class
d) When a parent class provides the same implementation of a method already defined in
its child class
Answer: a) When a child class provides a di erent implementation of a method already
defined in its parent class
12. Can a child class inherit the static members of its parent class?
a) Yes
b) No
Answer: a) Yes
13. Can a child class override the static methods of its parent class?
a) Yes
b) No
Answer: b) No
14. What is the purpose of the super keyword in Java?
a) To access the members of the parent class
b) To access the members of the child class
c) To create a new object
d) To override a method
Answer: a) To access the members of the parent class
15. Can a child class use the super keyword to access the private members of its parent
class?
A) Yes
b) No
Answer: a) Yes
16. What is the di erence between this and super keywords in Java?
a) this refers to the parent class, super refers to the current class
b) this refers to the current class, super refers to the parent class
c) this is used for methods, super is used for variables
d) this is used for variables, super is used for methods
Answer: b) this refers to the current class, super refers to the parent class
17. Can a child class inherit the constructors of its parent class?
a) Yes
b) No
Answer: b) No
18. Can a child class call the constructors of its parent class using the super keyword?
a) Yes
b) No
Answer: a) Yes
THIS keyword:
Questions
1. What is the purpose of the “this” keyword in Java?
a) To access parent class members
b) To access current class members
c) To create a new object
d) To override a method
Answer: b) To access current class members
2. Which of the following is a correct usage of the “this” keyword?
a) this = new MyClass();
b) MyClass obj = this;
c) this();
d) [Link]();
Answer: d) [Link]()
3. What does the “this” keyword refer to?
a) Parent class object
b) Current class object
c) Static method
d) Instance variable
Answer: b) Current class object
4. Can the “this” keyword be used in a static method?
a) Yes
b) No
Answer: b) No
5. What is the return type of the “this” keyword?
a) void
b) Object
c) Class
d) Interface
Answer: b) Object
6. Can the “this” keyword be used to call a constructor?
a) Yes
b) No
Answer: a) Yes
7. What is the purpose of “this()” in Java?
a) To call a method
b) To call a constructor
c) To access a variable
d) To create an object
Answer: b) To call a constructor
8. Can the “this” keyword be used in an interface?
a) Yes
b) No
Answer: b) No
9. What is the di erence between “this” and “super” keywords?
a) “this” refers to parent class, “super” refers to current class
b) “this” refers to current class, “super” refers to parent class
c) “this” is used for methods, “super” is used for variables
d) “this” is used for variables, “super” is used for methods
Answer: b) “this” refers to current class, “super” refers to parent class
10. Can the “this” keyword be used to return the current object?
a) Yes
b) No
Answer: a) Yes
11. What is the scope of the “this” keyword?
a) Local
b) Instance
c) Static
d) Global
Answer: b) Instance
12. Can the “this” keyword be used in a nested class?
a) Yes
b) No
Answer: a) Yes
13. What is the purpose of “this” in a constructor?
a) To call a method
b) To call another constructor
c) To access a variable
d) To create an object
Answer: b) To call another constructor
14. Can the “this” keyword be used with “static” keyword?
a) Yes
b) No
Answer: b) No
15. What is the benefit of using the “this” keyword?
a) Improves code readability
b) Reduces code length
c) Increases code complexity
d) Enhances code security
Answer: a) Improves code readability
SUPER KEYWORD
Questions
1. What is the purpose of the “super” keyword in Java?
a) To access the members of the parent class
b) To access the members of the child class
c) To create a new object
d) To override a method
Answer: a) To access the members of the parent class
2. Can the “super” keyword be used to access the private members of the parent class?
a) Yes
b) No
Answer: a) Yes
3. Can the “super” keyword be used to access the static members of the parent class?
A) Yes
b) No
Answer: a) Yes
4. Can the “super” keyword be used to call the constructors of the parent class?
a) Yes
b) No
Answer: a) Yes
5. What is the syntax to call the constructor of the parent class using “super”?
a) super();
b) super(keyword);
c) this. Super();
d) super(this);
Answer: a) super();
6. Can the “super” keyword be used in a static method?
a) Yes
b) No
Answer: b) No
7. Can the “super” keyword be used in an interface?
a) Yes
b) No
Answer: b) No
8. What is the di erence between “this” and “super” keywords?
a) this refers to the parent class, super refers to the current class
b) this refers to the current class, super refers to the parent class
c) this is used for methods, super is used for variables
d) this is used for variables, super is used for methods
Answer: b) this refers to the current class, super refers to the parent class
9. Can the “super” keyword be used to access the members of the grandparent class?
a) Yes
b) No
Answer: b) No
10. Can the “super” keyword be used in a nested class?
a) Yes
b) No
Answer: a) Yes
11. What is the scope of the “super” keyword?
a) Local
b) Instance
c) Static
d) Global
Answer: b) Instance
12. Can the “super” keyword be used with the “this” keyword?
a) Yes
b) No
Answer: a) Yes
13. Can the “super” keyword be used to call the methods of the parent class?
a) Yes
b) No
Answer: a) Yes
14. Can the “super” keyword be used to access the protected members of the parent
class?
A) Yes
b) No
Answer: a) Yes
15. Can the “super” keyword be used with lambda expressions?
a) Yes
b) No
Answer: a) Yes
16. Can the “super” keyword be used with method references?
a) Yes
b) No
Answer: a) Yes
17. What is the advantage of using the “super” keyword?
a) Improves code readability
b) Reduces code length
c) Increases code complexity
d) Enhances code security
Answer: a) Improves code readability
18. Can the “super” keyword be used in an abstract class?
a) Yes
b) No
Answer: a) Yes
19. Can the “super” keyword be used in an interface?
a) Yes
b) No
Answer: b) No
20. What happens when the “super” keyword is used to call a method that does not exist in
the parent class?
A) Compiler error
b) Runtime error
c) The method is called from the grandparent class
d) The method is called from the current class
Answer: a) Compiler error
METHOD OVERLOADING
Questions
1. What is method overloading in Java?
a) Defining multiple methods with the same name and di erent parameters
b) Defining multiple methods with di erent names and same parameters
c) Defining a single method with multiple names
d) Defining a single method with no name
Answer: a) Defining multiple methods with the same name and di erent parameters
2. What is the benefit of method overloading in Java?
a) Improves code readability
b) Reduces code length
c) Increases code complexity
d) Enhances code security
Answer: b) Reduces code length
3. Can method overloading be achieved by changing the return type of the method?
a) Yes
b) No
Answer: b) No
4. Can method overloading be achieved by changing the access modifier of the method?
a) Yes
b) No
Answer: b) No
5. What is the rule for method overloading in Java?
a) Methods must have the same name and di erent parameters
b) Methods must have di erent names and the same parameters
c) Methods must have the same name and the same parameters
d) Methods must have di erent names and di erent parameters
Answer: a) Methods must have the same name and di erent parameters
6. Can method overloading be used with constructors?
a) Yes
b) No
Answer: a) Yes
7. Can method overloading be used with static methods?
a) Yes
b) No
Answer: a) Yes
8. Can method overloading be used with abstract methods?
a) Yes
b) No
Answer: a) Yes
9. Can method overloading be used with final methods?
a) Yes
b) No
Answer: a) Yes
10. What happens when multiple methods with the same name are defined with di erent
parameters?
A) Compiler error
b) Runtime error
c) Method overloading
d) Method overriding
Answer: c) Method overloading
11. Can method overloading be achieved by changing the type of the parameters?
a) Yes
b) No
Answer: a) Yes
12. Can method overloading be achieved by changing the number of parameters?
a) Yes
b) No
Answer: a) Yes
13. Can method overloading be achieved by changing the order of the parameters?
a) Yes
b) No
Answer: b) No
14. What is the di erence between method overloading and method overriding?
a) Method overloading is used for static methods, method overriding is used for instance
methods
b) Method overloading is used for instance methods, method overriding is used for static
methods
c) Method overloading is used for methods with the same name and di erent parameters,
method overriding is used for methods with the same name and same parameters
d) Method overloading is used for methods with the same name and same parameters,
method overriding is used for methods with the same name and di erent parameters
Answer: c) Method overloading is used for methods with the same name and di erent
parameters, method overriding is used for methods with the same name and same
parameters
15. Can method overloading be used with varargs?
a) Yes
b) No
Answer: a) Yes
16. Can method overloading be used with generics?
a) Yes
b) No
Answer: a) Yes
17. What happens when a method is called with a parameter that matches multiple
overloaded methods?
A) Compiler error
b) Runtime error
c) The method with the closest matching parameter is called
d) The method with the most specific parameter is called
Answer: d) The method with the most specific parameter is called
18. Can method overloading be used with lambda expressions?
a) Yes
b) No
Answer: a) Yes
19. Can method overloading be used with method references?
a) Yes
b) No
Answer: a) Yes
20. What is the advantage of using method overloading in Java?
a) Improves code readability
b) Reduces code length
c) Increases code complexity
d) Enhances code security
Answer: b) Reduces code length
METHOD OVERRIDING
Questions
1. What is method overriding in Java?
a) Defining a method with the same name and parameters as a method in its superclass
b) Defining a method with a di erent name and parameters as a method in its superclass
c) ”defining a method with the same name and di erent parameters as a method in its
superclass
d) Defining a method with a di erent name and same parameters as a method in its
superclass
Answer: a) Defining a method with the same name and parameters as a method in its
superclass
2. What is the purpose of method overriding in Java?
a) To provide a specific implementation for a method in a subclass
b) To provide a generic implementation for a method in a superclass
c) To increase code complexity
d) To decrease code readability
Answer: a) To provide a specific implementation for a method in a subclass
3. Can method overriding be achieved by changing the return type of the method?
a) Yes
b) No
Answer: b) No
4. Can method overriding be achieved by changing the access modifier of the method?
a) Yes
b) No
Answer: a) Yes
5. What is the rule for method overriding in Java?
a) Methods must have the same name, parameters, and return type
b) Methods must have the same name and parameters but di erent return types
c) Methods must have the same name and return type but di erent parameters
d) Methods must have di erent names and parameters
Answer: a) Methods must have the same name, parameters, and return type
6. Can method overriding be used with abstract methods?
a) Yes
b) No
Answer: a) Yes
7. Can method overriding be used with final methods?
a) Yes
b) No
Answer: b) No
8. Can method overriding be used with static methods?
a) Yes
b) No
Answer: b) No
9. What happens when a subclass overrides a method of its superclass?
a) The subclass method hides the superclass method
b) The subclass method overrides the superclass method
c) The subclass method overloads the superclass method
d) The subclass method does not a ect the superclass method
Answer: b) The subclass method overrides the superclass method
10. Can method overriding be used with constructors?
a) Yes
b) No
Answer: b) No
11. What is the di erence between method overloading and method overriding?
a) Method overloading is used for static methods, method overriding is used for instance
methods
b) Method overloading is used for instance methods, method overriding is used for static
methods
c) Method overloading is used for methods with the same name and di erent parameters,
method overriding is used for methods with the same name and same parameters
d) Method overloading is used for methods with the same name and same parameters,
method overriding is used for methods with the same name and di erent parameters
Answer: c) Method overloading is used for methods with the same name and di erent
parameters, method overriding is used for methods with the same name and same
parameters
12. Can method overriding be used with varargs?
a) Yes
b) No
Answer: a) Yes
13. Can method overriding be used with generics?
a) Yes
b) No
Answer: a) Yes
14. What happens when a method is called on a subclass object that overrides a method of
its superclass?
a) The subclass method is called
b) The superclass method is called
c) Both methods are called
d) Neither method is called
Answer: a) The subclass method is called
15. Can method overriding be used with lambda expressions?
a) Yes
b) No
Answer: a) Yes
16. Can method overriding be used with method references?
a) Yes
b) No
Answer: a) Yes
17. What is the advantage of using method overriding in Java?
a) Improves code readability
b) Reduces code length
c) Increases code complexity
d) Enhances code security
Answer: a) Improves code readability
18. Can method overriding be used with abstract classes?
a) Yes
b) No
Answer: a) Yes
19. Can method overriding be used with interfaces?
a) Yes
b) No
Answer: a) Yes
20. What is the purpose of the @Override annotation in Java?
a) To indicate that a method is being overridden
b) To indicate that a method is being overloaded
c) To indicate that a method is being hidden
d) To indicate that a method is being shadowed
Answer: a) To indicate that a method is being overridden
ABSTRACT CLASSES
Questions
1. What is an abstract class in Java?
a) A class that can be instantiated
b) A class that cannot be instantiated
c) A class that can only be extended
d) A class that cannot be extended
Answer: b) A class that cannot be instantiated
2. What is the purpose of an abstract class in Java?
a) To provide a complete implementation
b) To provide a partial implementation
c) To provide a full implementation
d) To provide no implementation
Answer: b) To provide a partial implementation
3. Can an abstract class have constructors?
a) Yes
b) No
Answer: a) Yes
4. Can an abstract class have static methods?
a) Yes
b) No
Answer: a) Yes
5. Can an abstract class have abstract methods?
a) Yes
b) No
Answer: a) Yes
6. What is an abstract method in Java?
a) A method with a body
b) A method without a body
c) A method with a return type
d) A method without a return type
Answer: b) A method without a body
7. Can a subclass of an abstract class be abstract?
a) Yes
b) No
Answer: a) Yes
8. Can an abstract class implement an interface?
a) Yes
b) No
Answer: a) Yes
9. Can an abstract class extend another abstract class?
a) Yes
b) No
Answer: a) Yes
10. What happens when an abstract class is extended by a concrete subclass?
a) The concrete subclass must implement all abstract methods
b) The concrete subclass does not need to implement any abstract methods
c) The concrete subclass can choose which abstract methods to implement
d) The concrete subclass cannot implement any abstract methods
Answer: a) The concrete subclass must implement all abstract methods
11. Can an abstract class have a private constructor?
a) Yes
b) No
Answer: a) Yes
12. Can an abstract class have a protected constructor?
a) Yes
b) No
Answer: a) Yes
13. Can an abstract class have a public constructor?
a) Yes
b) No
Answer: a) Yes
14. What is the di erence between an abstract class and an interface in Java?
a) An abstract class can have state, an interface cannot
b) An abstract class cannot have state, an interface can
c) An abstract class can have behavior, an interface cannot
d) An abstract class cannot have behavior, an interface can
Answer: a) An abstract class can have state, an interface cannot
15. Can an abstract class be used as a type?
a) Yes
b) No
Answer: a) Yes
16. Can an abstract class be used as a parameter type?
a) Yes
b) No
Answer: a) Yes
17. Can an abstract class be used as a return type?
a) Yes
b) No
Answer: a) Yes
18. What is the benefit of using an abstract class in Java?
a) Improves code readability
b) Reduces code length
c) Increases code complexity
d) Enhances code security
Answer: a) Improves code readability
19. Can an abstract class be used in a multi-level inheritance hierarchy?
a) Yes
b) No
Answer: a) Yes
20. Can an abstract class be used in a hierarchical inheritance hierarchy?
a) Yes
b) No
Answer: a) Yes
DYNAMIC METHOD DISPATCH
Questions
1. What is dynamic method dispatch in Java?
a) The process of resolving method calls at compile-time
b) The process of resolving method calls at runtime
c) The process of overriding methods
d) The process of overloading methods
Answer: b) The process of resolving method calls at runtime
2. Which mechanism is used to implement dynamic method dispatch in Java?
a) Method overriding
b) Method overloading
c) Operator overloading
d) Function overloading
Answer: a) Method overriding
3. What is the purpose of dynamic method dispatch in Java?
a) To improve code readability
b) To reduce code length
c) To enable polymorphism
d) To disable polymorphism
Answer: c) To enable polymorphism
4. Can dynamic method dispatch be achieved without method overriding?
a) Yes
b) No
Answer: b) No
5. Can dynamic method dispatch be achieved without inheritance?
a) Yes
b) No
Answer: b) No
6. What is the di erence between static method dispatch and dynamic method dispatch?
a) Static method dispatch occurs at compile-time, dynamic method dispatch occurs at
runtime
b) Static method dispatch occurs at runtime, dynamic method dispatch occurs at compile-
time
c) Static method dispatch is used for method overriding, dynamic method dispatch is used
for method overloading
d) Static method dispatch is used for method overloading, dynamic method dispatch is
used for method overriding
Answer: a) Static method dispatch occurs at compile-time, dynamic method dispatch
occurs at runtime
7. Can dynamic method dispatch be used with abstract classes?
a) Yes
b) No
Answer: a) Yes
8. Can dynamic method dispatch be used with interfaces?
a) Yes
b) No
Answer: a) Yes
9. What happens when a subclass overrides a method of its superclass?
a) The subclass method hides the superclass method
b) The subclass method overrides the superclass method
c) The subclass method overloads the superclass method
d) The subclass method does not a ect the superclass method
Answer: b) The subclass method overrides the superclass method
10. Can dynamic method dispatch be used with multiple levels of inheritance?
a) Yes
b) No
Answer: a) Yes
11. Can dynamic method dispatch be used with hierarchical inheritance?
a) Yes
b) No
Answer: a) Yes
12. What is the benefit of using dynamic method dispatch in Java?
a) Improves code readability
b) Reduces code length
c) Enables polymorphism
d) Disables polymorphism
Answer: c) Enables polymorphism
13. Can dynamic method dispatch be used with method overloading?
a) Yes
b) No
Answer: b) No
14. Can dynamic method dispatch be used with constructor overloading?
a) Yes
b) No
Answer: b) No
15. What happens when a method is called on a subclass object that overrides a method of
its superclass?
a) The subclass method is called
b) The superclass method is called
c) Both methods are called
d) Neither method is called
Answer: a) The subclass method is called
16. Can dynamic method dispatch be used with anonymous classes?
a) Yes
b) No
Answer: a) Yes
17. Can dynamic method dispatch be used with lambda expressions?
a) Yes
b) No
Answer: a) Yes
18. What is the di erence between dynamic method dispatch and method overriding?
a) Dynamic method dispatch is used for method overloading, method overriding is used for
method overriding
b) Dynamic method dispatch is used for method overriding, method overriding is used for
method overloading
c) Dynamic method dispatch is used for runtime polymorphism, method overriding is used
for compile-time polymorphism
d) Dynamic method dispatch is used for compile-time polymorphism, method overriding is
used for runtime polymorphism
Answer: c) Dynamic method dispatch is used for runtime polymorphism, method
overriding is used for compile-time polymorphism
19. Can dynamic method dispatch be used with abstract methods?
a) Yes
b) No
Answer: a) Yes
20. What is the purpose of the “super” keyword in dynamic method dispatch?
a) To call the superclass method
b) To call the subclass method
c) To override the superclass method
d) To overload the superclass method
Answer: a) To call the superclass method
FINAL KEYWORD
Questions
1. What is the purpose of the final keyword in Java?
a) To declare a variable that can be changed
b) To declare a variable that cannot be changed
c) To declare a method that can be overridden
d) To declare a method that cannot be overridden
Answer: b) To declare a variable that cannot be changed
2. Can a final variable be reassigned?
a) Yes
b) No
Answer: b) No
3. Can a final method be overridden?
a) Yes
b) No
Answer: b) No
4. Can a final class be subclassed?
a) Yes
b) No
Answer: b) No
5. What happens when a final variable is declared but not initialized?
a) Compiler error
b) Runtime error
c) The variable is initialized with a default value
d) The variable is not initialized
Answer: a) Compiler error
6. Can a final method be declared in an abstract class?
a) Yes
b) No
Answer: a) Yes
7. Can a final class be declared as abstract?
a) Yes
b) No
Answer: b) No
8. What is the benefit of using the final keyword with variables?
a) Improves code readability
b) Reduces code length
c) Prevents unintended changes
d) Increases code complexity
Answer: c) Prevents unintended changes
9. What is the benefit of using the final keyword with methods?
a) Improves code readability
b) Reduces code length
c) Prevents method overriding
d) Increases code complexity
Answer: c) Prevents method overriding
10. What is the benefit of using the final keyword with classes?
a) Improves code readability
b) Reduces code length
c) Prevents subclassing
d) Increases code complexity
Answer: c) Prevents subclassing
11. Can a final variable be declared as static?
a) Yes
b) No
Answer: a) Yes
12. Can a final method be declared as static?
a) Yes
b) No
Answer: a) Yes
13. Can a final class be declared as static?
a) Yes
b) No
Answer: b) No
14. What happens when a final variable is declared as volatile?
a) Compiler error
b) Runtime error
c) The variable is not volatile
d) The variable is volatile
Answer: d) The variable is volatile
15. What happens when a final method is declared as synchronized?
a) Compiler error
b) Runtime error
c) The method is not synchronized
d) The method is synchronized
Answer: d) The method is synchronized
16. Can a final class be declared as abstract and final?
a) Yes
b) No
Answer: b) No
17. Can a final method be declared as abstract and final?
a) Yes
b) No
Answer: b) No
18. Can a final variable be declared as transient?
a) Yes
b) No
Answer: a) Yes
19. Can a final method be declared as native?
a) Yes
b) No
Answer: a) Yes
20. Can a final class be declared as strictfp?
a) Yes
b) No
Answer: a) Yes
21. What is the e ect of declaring a variable as final in a constructor?
a) The variable can be changed
b) The variable cannot be changed
c) The variable is initialized with a default value
d) The variable is not initialized
Answer: b) The variable cannot be changed
22. What is the e ect of declaring a method as final in an abstract class?
a) The method can be overridden
b) The method cannot be overridden
c) The method is abstract
d) The method is not abstract
Answer: b) The method cannot be overridden
23. What is the e ect of declaring a class as final and abstract?
a) The class can be subclassed
b) The class cannot be subclassed
c) The class is abstract
d) The class is not abstract
Answer: b) The class cannot be subclassed
24. Can a final variable be used as a constant?
a) Yes
b) No
Answer: a) Yes
25. Can a final method be used as a hook method?
a) Yes
b) No
Answer: a) Yes