this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.
From within a constructor, you can also use the this keyword to call another constructor in the same class. Doing so is called an explicit constructor invocation. Here's another Rectangle class, with a different implementation from the one in the Objects section. public class Rectangle { private int x, y; private int width, height;
public Rectangle() { this(0, 0, 0, 0); } public Rectangle(int width, int height) { this(0, 0, width, height); } public Rectangle(int x, int y, int width, int height) { this.x = x; this.y = y; this.width = width; this.height = height; } ... } This class contains a set of constructors. Each constructor initializes some or all of the rectangle's member variables. The constructors provide a default value for any member variable whose initial value is not provided by an argument. For example, the no-argument constructor calls the four-argument constructor with four 0 values and the two-argument constructor calls the four-argument constructor with two 0 values. As before, the compiler determines which constructor to call, based on the number and the type of arguments. If present, the invocation of another constructor must be the first line in the constructor.
Super()
With super(), the superclass no-argument constructor is called. With super(parameter list), the superclass constructor with a matching parameter list is called.
This could be a problem, if there is a constructor in the superclass that does a lot of necessary work. It looks like you might have to repeat all that work in the subclass! This could be a real problem if you don't have the source code to the superclass, and don't know how it works, or if the constructor in the superclass initializes private member variables that you don't even have access to in the subclass!
Obviously, there has to be some fix for this, and there is. It involves the special variable, super(). As the very first statement in a constructor, you can use super to call a constructor from the superclass.
1.this is keyword is used to resolve the conflict between local and instance variable. 2.this is keyword is used to acess all the members of same class. 3.this() should also be used in the first line of the constuctor i.e why this() & super()cannot be used in the same constructor. 4.this is keyword which refers to the current object getting created. 5.this is also used for constructor chaining-Invoking one constructor from another constructor. 6.We can do constructor chaining with this() & super().this() will create the chaining among the constructors within the same class & super will create in super classes. Eg: class A { A() { this(1,"s"); System.out.println("1st costructor");