Java_Exam_Preparation_Notes_Part1
Java_Exam_Preparation_Notes_Part1
5. Explain all 3 usages of final. What is the use of this and super keyword?
final:
- final variable: Value can’t change.
- final method: Cannot be overridden.
- final class: Cannot be inherited.
this keyword:
- Refers to current object.
- Used to resolve variable name conflicts.
- Can call another constructor.
super keyword:
- Refers to parent class.
- Used to call parent constructor or method.
8. How can a derived class constructor pass argument to base class constructor?
Using super():
Example:
class Child extends Parent {
Child() {
super("value"); // passes to Parent constructor
}
}
9. What is the difference between an abstract class and an interface in Java?
Abstract Class:
- Can have abstract and concrete methods.
- Can have constructors.
- Single inheritance.
Interface:
- Only abstract methods (Java 7) or default/static (Java 8+).
- No constructors.
- Multiple inheritance supported.
11. What are the uses of “super” and “this” keyword? Explain
this:
- Refers to current object.
- Calls other constructors.
super:
- Refers to parent class.
- Calls parent class constructor/methods.
12. Explain JVM, JRE and JDK with suitable diagrams and explain all
functionalities.
- JVM: Runs bytecode.
- JRE: JVM + libraries.
- JDK: JRE + development tools like compiler.
Diagram:
JDK
├── JRE
│ ├── JVM
│ └── Libraries
├── Compiler
├── Debugger
13. Explain Exception Handling with an example program. Discuss throw and
throws keywords.
try {
int a = 10/0;
} catch(Exception e) {
System.out.println("Error");
}