Which of the following correctly implements method overloading rules in Java?
AMethods must have the same name and same parameter types
BMethods must have the same name but different parameter types, number, or order
CMethods must have different names and different return types
DMethods can have same name with different return types only
Correct Answer:
B. Methods must have the same name but different parameter types, number, or order
EXPLANATION
Method overloading requires methods to have the same name but different parameter lists (different types, number, or order of parameters). Return type alone cannot distinguish overloaded methods.
An abstract class in Java cannot be instantiated, but it can have concrete methods. Which statement explains why?
AAbstract classes are incomplete and cannot have objects
BAbstract classes serve as templates and concrete methods provide default implementations that subclasses can use
CAbstract methods do not allow concrete methods in the same class
DConcrete methods in abstract classes are automatically inherited as abstract
Correct Answer:
B. Abstract classes serve as templates and concrete methods provide default implementations that subclasses can use
EXPLANATION
Abstract classes cannot be instantiated but can contain both abstract methods (without implementation) and concrete methods (with implementation). This allows providing default behavior while enforcing certain methods to be implemented by subclasses.
Which of the following best describes polymorphism in Java?
AThe ability to create multiple classes from a single parent class
BThe ability of an object to take multiple forms or for objects to behave differently in different contexts
CThe ability to hide internal implementation details
DThe ability to combine data and methods in a single unit
Correct Answer:
B. The ability of an object to take multiple forms or for objects to behave differently in different contexts
EXPLANATION
Polymorphism allows objects to be treated as instances of their parent class and to call methods that are overridden in child classes. It includes method overloading and method overriding.
What is the difference between 'this' and 'super' keywords in Java?
A'this' refers to parent class and 'super' refers to current class
B'this' refers to current class object and 'super' refers to parent class
CBoth are identical and can be used interchangeably
D'this' is used in interfaces and 'super' is used in abstract classes
Correct Answer:
B. 'this' refers to current class object and 'super' refers to parent class
EXPLANATION
'this' is a reference to the current object instance, while 'super' is a reference to the parent class object. They are used to access members of current and parent classes respectively.
In the context of constructors, which statement is correct?
AConstructors can have return types
BA class can have multiple constructors with different parameter lists
CConstructors are inherited like other methods
DConstructors must be declared as public
Correct Answer:
B. A class can have multiple constructors with different parameter lists
EXPLANATION
Constructor overloading is allowed in Java. A class can have multiple constructors with different parameter lists. Constructors don't have return types and can have any access modifier.
Which of the following correctly describes method overriding in Java?
AMethods with the same name but different parameters in the same class
BMethods with the same signature in parent and child classes with @Override annotation
CCreating multiple methods with same name in different classes
DMethods that cannot be inherited
Correct Answer:
B. Methods with the same signature in parent and child classes with @Override annotation
EXPLANATION
Method overriding occurs when a child class provides a specific implementation of a method already defined in the parent class with the same signature. The @Override annotation is optional but recommended.
Which of the following statements about inheritance in Java is correct?
AA class can inherit from multiple classes directly
BA class can implement multiple interfaces
CAn interface can extend multiple interfaces
DBoth B and C are correct
Correct Answer:
D. Both B and C are correct
EXPLANATION
Java supports single inheritance for classes but a class can implement multiple interfaces. An interface can extend multiple interfaces through multiple inheritance.