KwickAcademy Java · 5 min · free
Constructors and the this Keyword
What a constructor does, the three kinds, the missing default trap, constructor overloading, and the four rules of this.
Follows the syllabus of: ICSE Class 10 Computer Applications, ISC Class 12 Computer Science (868), GSEB Std 12 Computer Studies
On screen in this lesson
Definition, then three rules
| A special member that sets up a new object |
| Same name as the class |
| No return type, not even void |
| Runs automatically when new creates an object |
Kinds of constructors
| Kind | Parameters | Example |
|---|---|---|
| Non-parameterised | none | Stu() |
| Parameterised | one or more | Stu(String nm) |
| Java's hidden one | none, hidden | if you write none |
Pause and predict: the trap
| Class has only Stu(String nm, int mk) |
| We write: new Stu() |
| Java no longer adds the hidden default |
| Result: compile error, constructor not found |
The this keyword
| this means the current object |
| this.name is the field, name is the parameter |
| this() calls another constructor of the same class |
| this() must be the first statement |
| No this inside a static method |
Constructor vs method
| Point | Constructor | Method |
|---|---|---|
| Name | same as class | any valid name |
| Return type | none | needed, or void |
| Called | automatically | by its name |
| Purpose | set up an object | do a task |
| Inherited? | no | yes |
Quick recap
| Constructor: same name as class, no return type |
| Runs automatically with new |
| Write any constructor and the hidden default goes |
| Overloading: many constructors, different parameters |
| this: current object; this() must come first |
Quick answers
Why does new Stu() fail after you write Stu(String, int)?
Once you write any constructor, Java no longer adds the hidden default one.
Why print null when you write name = name?
The parameter hides the field. Use this.name = name.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
Who gives a new object its starting values?38 sec
Why does new Stu() give an error?41 sec
Can a class have two constructors?39 sec
Why does the field print null?40 sec
What is the first difference?39 secThe full lesson, in text
Hello students, welcome to Kwickprep. When a new student joins school, the office fills in a form before anything else. Java objects need the same first step. Today we will learn constructors, the this keyword, and a trap that gives a compile error.
A constructor has one job, and it follows three rules. It is a special member of a class that gives starting values to a new object. This is called initialising the object. Its name is exactly the same as the class name. It has no return type, not even void. And it runs automatically when we create an object with the keyword new.
Here the class is Stu, short for student, with a name and marks. The constructor Stu, with empty brackets, sets the name to New and marks to zero. In main, new Stu creates an object called obj. We never call the constructor ourselves, it runs by itself. So it prints New, and then zero.
There are three kinds you should know. A non-parameterised constructor takes no values, and many textbooks call it a default constructor too. A parameterised constructor takes values, so each object can start differently. If you write no constructor at all, Java adds a hidden default one, which gives zero, false or null to every field.
Now the constructor takes two parameters, nm for name and mk for marks. When we write new Stu with Riya and ninety one, those values go straight into the new object. So each student can start with their own data. It prints Riya.
Pause and predict this trap. Our class has only the parameterised constructor. In main, we write new Stu with empty brackets. Does it work? No. Once you write any constructor, Java stops adding the hidden default one. So the compiler says it cannot find a constructor with no arguments.
Just like methods, constructors can be overloaded. That means one class has several constructors with different parameter lists. The first Box takes one side, for a square, and stores it in both length and width. The second takes a length and a width, for a rectangle. New Box of four matches the one parameter version, so the area is sixteen. New Box of two and three would give six.
Now the keyword this, which has five rules. This refers to the current object, the one being built or used right now. When a parameter has the same name as a field, this dot name means the field. This with brackets calls another constructor of the same class. That call must be the very first statement in the constructor. And you cannot use this inside a static method, because there is no current object.
Here the parameter and the field are both called name. The parameter hides the field inside the constructor. This dot name means the field of this object, and the plain name means the parameter. So Aman is stored, and it prints Aman. If you wrote name equals name without this, the field would stay null, and it would print null.
This with brackets lets one constructor reuse another. The one side constructor simply calls the two value constructor, passing side twice. So we write the setting up code only once. New Box of five makes a five by five square, and it prints twenty five.
Exams often ask for the differences between a constructor and a method. A constructor's name matches the class, but a method can have any valid name. A constructor has no return type, while a method needs one, or void. A constructor runs automatically with new, while a method runs when you call it by name. A constructor sets up an object, and a method does a task. Finally, a child class does not inherit constructors, but it does inherit methods.
Let us revise what we learned today. A constructor has the same name as the class and no return type. It runs automatically when new creates an object. Once you write any constructor, Java no longer adds the hidden default one. A class can overload constructors with different parameter lists. This means the current object, and this with brackets must be the first statement.
Courses that teach this
| Course | Unit |
|---|---|
| ICSE Class 10 Computer Applications | Constructors |
| ISC Class 12 Computer Science (868) | Functions (Methods) |
| GSEB Std 12 Computer Studies | Classes, Objects, Arrays and Strings in Java |
| Programming All levels Java | Classes, Objects and Methods |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

