Object Oriented Programming Using Java – Unit III Q&A
1. What is an interface?
An interface in Java is a collection of
abstract methods and
static constants.
It is used to achieve full abstraction
and multiple inheritance.
2. Define method overriding.
Method overriding occurs when a
subclass provides a specific implementation
of a method already defined in its
superclass.
The method must have the same
name, return type, and parameters.
3. What is dynamic method dispatch?
Dynamic method dispatch is a mechanism where
method calls are resolved at runtime
instead of compile-time.
It supports runtime polymorphism.
4. What is the purpose of super keyword?
The super keyword refers to the
immediate parent class object and removes
confusion between superclass and subclass members.
5. Mention any two uses of super.
1. To call the parent class constructor.
2. To access parent class variables or methods.
2. To access parent class variables or methods.
6. What is an abstract class?
An abstract class is declared using the
abstract keyword and cannot be instantiated.
It may contain both abstract and
concrete methods.
8. What is the use of final keyword?
The final keyword restricts modification.
It can make variables constant,
prevent method overriding,
and stop inheritance.
10. What is a package in Java?
A package is a collection of related
classes and interfaces used to organize code
and avoid naming conflicts.
12. What is an exception?
An exception is an unexpected event that
occurs at runtime and disrupts
normal program flow.
13. What is the purpose of try–catch block?
The try block contains risky code,
while the catch block handles exceptions
to prevent program crashes.
15. What is the difference between throw and throws?
throw is used to explicitly throw an exception.
throws is used in a method signature to declare exceptions.
throws is used in a method signature to declare exceptions.
16. What is a user-defined exception?
A user-defined exception is created by extending
java.lang.Exception to handle custom application errors.
0 Comments