Govt. Exams
Entrance Exams
'final' keyword makes a variable immutable. Once assigned, its value cannot be changed. 'const' is not a valid Java keyword.
'this' is a reference to the current object instance. It's used to refer to instance variables, call other constructors, or pass object reference.
Set interface ensures uniqueness and doesn't allow duplicate elements. HashSet, TreeSet are implementations of Set.
The 'super' keyword is used to refer to the immediate parent class object. It's used to access parent class methods and constructors.
class Parent {
void show() {
System.out.println("Parent");
}
}
class Child extends Parent {
void show() {
System.out.println("Child");
}
}
parent obj = new Child();
obj.show();
This demonstrates method overriding and polymorphism. The actual object type is Child, so Child's show() method is called.
Default access (no modifier) allows access only within the same package. Protected allows same package and subclasses.
The four pillars of OOP are Abstraction, Encapsulation, Inheritance, and Polymorphism. Compilation is a process, not a pillar of OOP.