Govt. Exams
Entrance Exams
'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.
All three declarations are syntactically valid in Java and represent the same 2D array structure. The position of brackets doesn't matter for 2D array declaration - they all create a 3x4 integer array.
String s = "Java";
s = s.concat(" Programming");
System.out.println(s.length());
"Java" has 4 characters. After concatenation with " Programming" (12 characters including space), the total length is 4 + 13 = 17 characters.
int[] arr = new int[5];
System.out.println(arr[5]);
An array of size 5 has valid indices from 0 to 4. Accessing arr[5] throws ArrayIndexOutOfBoundsException at runtime because index 5 is out of bounds.
Java's garbage collector automatically identifies and reclaims memory of objects that are no longer referenced. While System.gc() can be suggested, it's not guaranteed to execute immediately.