What is the purpose of the this keyword in Java?
this refers to the current object instance whose method or constructor is being executed.
When is this used to resolve variable conflicts?
It is used when instance variables are shadowed by method parameters or local variables with the same name.
Example use of this for variable shadowing?
this.x = x assigns parameter x to instance variable x.
Can this be used to call another constructor?
Yes. this() calls another constructor in the same class.
When must this() be used in a constructor?
It must be the first statement in the constructor.
Can this be used to call methods?
Yes. this.methodName() explicitly calls a method of the current object.
Is using this to call methods required?
No. It is optional unless disambiguation is needed.
Can this refer to static members?
No. this refers only to instance context, not static context.
What happens if you use this inside a static method?
It causes a compile-time error because static methods have no instance.
Can this be returned from a method?
Yes. Returning this returns the current object reference.
What is constructor chaining using this?
It is the process of calling one constructor from another within the same class using this().
Difference between this and super?
this refers to current class instance, while super refers to the parent class instance.
Does this change during object lifetime?
No. It always refers to the current object instance for that method call.
Can this be passed as a parameter?
Yes. You can pass the current object reference to another method or constructor.
Is this available inside constructors?
Yes. It refers to the object being constructed.
What is inheritance in Java?
Inheritance is an OOP mechanism where one class acquires properties and methods of another class using extends.
What is the main purpose of inheritance?
It promotes code reuse and allows shared logic to be defined in a base (superclass) and reused by subclasses.
What is an IS-A relationship in inheritance?
It means a subclass is a specialized type of its superclass, e.g., Dog IS-A Animal.
What keyword is used to implement inheritance in Java?
extends.
What is a superclass?
A superclass is the parent class whose members are inherited by another class.
What is a subclass?
A subclass is a child class that inherits fields and methods from a superclass.
Does Java support multiple inheritance with classes?
No. Java supports single inheritance for classes but allows multiple inheritance through interfaces.
What is inherited from a superclass?
Accessible fields, methods, and behaviors are inherited, but constructors are not.
Can private members be inherited?
They are technically inherited but not directly accessible in subclasses.