Kit Library / Computer Science / Object-Oriented Programming

⚡ Topic Learning Kit

Java OOP

English 17 leveled MCQs 16 flashcards 6 games Free

Shared by a Veda teacher · Generated with Veda AI

Veda Bites

The whole idea, one bite at a time

Veda Bites are swipeable micro-lessons — each one teaches exactly one idea. The bites below come from this kit — swipe through them in the app.

💡 Key Idea

`this` is a reference to the current object

Your object's self-portrait.

Inside any instance method or constructor, `this` is a reference variable that points to the object on which the method was invoked. It lets an object refer to itself.

↳ `this` always means 'the object I am working on right now'.

📖 Definition

What exactly is `this`?

Not a variable you declare.

`this` is a final reference that Java automatically provides inside every instance context. You never declare it; it is implicitly available in instance methods, constructors, and instance initializer blocks.

↳ `this` is an implicit, read-only reference to the current object.

⚠️ Common Mistake

Using `this` inside a static method

Static has no object.

A static method belongs to the class, not to any object. Since there is no current object, `this` cannot be used there. The compiler will reject it.

↳ No object, no `this` — static methods cannot use it.

🛠️ Application

Shadowing: field vs parameter

Same name, different scope.

When a constructor parameter or local variable has the same name as an instance field, the local one shadows the field. Use `this.fieldName` to refer to the field explicitly.

↳ `this.` disambiguates a shadowed field from a local variable.

⚙️ Process

Constructor chaining with `this()`

One constructor calls another.

Inside a constructor, `this(...)` invokes another constructor of the same class. This reduces code duplication. It must be the first statement in the constructor.

↳ `this(...)` chains constructors within the same class.

⚖️ Comparison

`this()` vs `super()`

Same class or parent?

↳ `this()` stays in the class; `super()` goes up to the parent.

🛠️ Application

Returning the current object

Fluent interfaces start here.

A method can return `this` to allow method chaining. This is common in builder patterns and fluent APIs.

↳ `return this;` enables chained method calls.

🛠️ Application

Passing `this` as an argument

Hand your object over.

You can pass `this` to another method or constructor when the current object needs to be used elsewhere, such as registering a listener or passing state to a helper.

↳ `this` can be passed like any other reference.

⭐ Important Fact

`this` is not available in static context

Static belongs to the class.

Static methods, static blocks, and static nested classes have no `this` because they are not tied to an instance. Trying to use `this` there causes a compile-time error.

↳ Static context = no current object = no `this`.

🧠 Memory Trick

Remember: `this` = 'me, the object'

Point to yourself.

Whenever you see `this`, read it as 'this object' or 'me'. If you are in a static method, there is no 'me' — only the class.

↳ `this` is the object's way of saying 'me'.

🎯 Exam Tip

Exam trap: `this` in constructors

First line only.

If you use `this(...)` to call another constructor, it must be the first statement. Placing it later causes a compile-time error. Also, you cannot use `this()` and `super()` together in the same constructor.

↳ `this()` must be the first statement in a constructor.

❓ Did You Know

`this` is a keyword, not a variable

Reserved and special.

`this` is a reserved keyword in Java. You cannot use it as an identifier, and you cannot assign to it. It is always provided by the JVM.

↳ `this` is a keyword — treat it as read-only.

Smart notes

What you'll study, topic by topic

1

The `this` Keyword in Java

8 min

The `this` keyword in Java is a reference to the current object. It is used to access instance fields and methods, resolve shadowing, chain constructors, and return the current object for method chaining. It is not avail…

  • `this` is a reference to the current object in Java.
  • It is used to access instance fields and methods, especially when shadowed by local variables.
  • `this()` calls another constructor of the same class and must be the first statement.

Full explanation, worked examples & memory tricks in the app

Leveled MCQ practice

Try the smart MCQs from this kit

All 17 questions, laddered from warm-up to topper-level, each with its answer and the reasoning behind it.

Warm-up · 5 questions

Q1. What does the `this` keyword refer to in Java?

Beginner
A The superclass object
B The current object
C The current method
D The current class
Show the answer

B · The current object

`this` is a reference to the current object whose method or constructor is being invoked.

Q2. Which of the following is a valid use of the `this` keyword?

Beginner
A To call another constructor in the same class
B To create a new object
C To access static variables
D To call a constructor in the superclass
Show the answer

A · To call another constructor in the same class

`this()` can be used to invoke another constructor of the same class. Calling a superclass constructor is done with `super()`.

Q3. Can `this` be used inside a static method?

Beginner
A Only if the method is final
B Only if the method is private
C No, never
D Yes, always
Show the answer

C · No, never

Static methods belong to the class, not to any instance, so `this` is not available.

Q4. The `this` keyword can be used to refer to the current object's instance variables.

Beginner
A True
B False
Show the answer

A · True

`this` is commonly used to access instance variables, especially when they are shadowed by local variables or parameters.

Q5. The `this` keyword can be used in a static method.

Beginner
A True
B False
Show the answer

B · False

Static methods are not associated with any instance, so `this` cannot be used inside them.

Building up · 11 questions

Q6. What is the output of the following code? ```java class Test { int x; Test(int x) { this.x = x; } void display() { System.out.println(x); } public static void main(String[] args) { Test t = new Test(10); t.display(); } } ```

Intermediate
A Runtime error
B Compilation error
C 10
D 0
Show the answer

C · 10

The constructor parameter `x` shadows the instance variable `x`. Using `this.x = x` assigns the parameter value to the instance variable. So `x` becomes 10.

Q7. Which statement about `this` is true?

Intermediate
A `this` can be used to refer to instance variables.
B `this` can be reassigned to refer to another object.
C `this` can be used in static methods.
D `this` is a keyword that can be used as an identifier.
Show the answer

A · `this` can be used to refer to instance variables.

`this` refers to the current object and is commonly used to access instance variables. It cannot be used in static contexts and cannot be reassigned.

Q8. What is the purpose of `this()` in a constructor?

Intermediate
A To create a new instance of the class
B To call a method of the current object
C To call a constructor of the superclass
D To call another constructor of the same class
Show the answer

D · To call another constructor of the same class

`this()` is used to invoke another constructor within the same class, enabling constructor chaining.

Q9. What is the output of the following code? ```java class A { A() { this(10); System.out.println("Default constructor"); } A(int x) { System.out.println("Parameterized constructor: " + x); } public static void main(String[] args) { new A(); } } ```

Intermediate
A Default constructor Parameterized constructor: 10
B Parameterized constructor: 10
C Parameterized constructor: 10 Default constructor
D Default constructor
Show the answer

C · Parameterized constructor: 10 Default constructor

The default constructor calls `this(10)`, which invokes the parameterized constructor first. After it completes, the default constructor continues and prints its message.

Q10. Which of the following is NOT a valid use of `this`?

Intermediate
A Passing `this` as an argument to a method
B Returning `this` from a method
C Using `this` to invoke an instance method
D Using `this` to access a static variable
Show the answer

D · Using `this` to access a static variable

`this` refers to the current object, so it cannot be used to access static members (which belong to the class, not an object).

Q11. What is the output of the following code? ```java class Test { int x = 5; void method() { int x = 10; System.out.println(this.x); } public static void main(String[] args) { new Test().method(); } } ```

Intermediate
A 10
B Compilation error
C 5
D 0
Show the answer

C · 5

`this.x` refers to the instance variable `x`, which is 5. The local variable `x` (10) is shadowing it, but `this.x` accesses the instance variable.

Q12. What does the following code do? ```java class Test { Test get() { return this; } public static void main(String[] args) { Test t = new Test().get(); System.out.println(t instanceof Test); } } ```

Intermediate
A Compilation error
B Prints false
C Runtime error
D Prints true
Show the answer

D · Prints true

The `get()` method returns the current object (`this`). The returned object is an instance of `Test`, so `t instanceof Test` is true.

Q13. Which of the following statements about `this` is false?

Intermediate
A `this` can be used to access static methods.
B `this` can be used to differentiate between instance variables and parameters with the same name.
C `this` can be passed as an argument to a method.
D `this` can be used to invoke another constructor of the same class.
Show the answer

A · `this` can be used to access static methods.

`this` cannot be used to access static methods because static methods are not associated with any particular instance.

Q14. What is the output of the following code? ```java class Test { int x; Test() { this(10); } Test(int x) { this.x = x; } void display() { System.out.println(x); } public static void main(String[] args) { new Test().display(); } } ```

Intermediate
A Runtime error
B 10
C 0
D Compilation error
Show the answer

B · 10

The default constructor calls `this(10)`, which sets `x` to 10. Then `display()` prints 10.

Q15. Which of the following is a valid way to use `this` to call a method?

Intermediate
A this->methodName();
B this.methodName();
C this::methodName();
D this.methodName;
Show the answer

B · this.methodName();

In Java, `this.methodName()` is the correct syntax to call an instance method on the current object.

Q16. Which of the following is true about `this` in Java?

Intermediate
A `this` is a reference to the current object.
B `this` is a keyword that can be used as a variable name.
C `this` is a reference to the superclass object.
D `this` can be used to access static variables.
Show the answer

A · `this` is a reference to the current object.

`this` is a reference to the current object. It cannot be used as a variable name, and it does not refer to the superclass.

Topper level · 1 questions

Q17. What is the output of the following code? ```java class Test { int x = 1; void method() { int x = 2; this.x = 3; System.out.println(x + this.x); } public static void main(String[] args) { new Test().method(); } } ```

Advanced
A 4
B 5
C 6
D 3
Show the answer

B · 5

Local variable `x` is 2. `this.x` is set to 3. So `x + this.x` is 2 + 3 = 5.

Flashcards

Tap a card to flip it

16 flashcards in this kit — the app reviews them with spaced repetition so the right card returns on the right day.

Learning games

Play your way through this kit

Every game is built from this kit's own content — scores feed your mastery, so playing counts as studying.

🎮

True False

Built from this kit's own content

🎮

Memory Match

Built from this kit's own content

🎮

Flashcard Battle

Built from this kit's own content

🎮

Speed Quiz

Built from this kit's own content

🎮

Sequence Builder

Built from this kit's own content

🎮

Revision Battle

Built from this kit's own content

Playable in the app

Study it properly — free, in the app

The full Veda Bites deck, complete notes, spaced-repetition flashcards, leveled MCQs, tests and games for this kit — plus Daily Facts and the Arena, every day.