Java Notesss
Java Notesss
Constructer in Java: -
1. Constructor is somewhat like a method but not exactly a method.
2. Constructor has same name as that of class.
3. There are three types of constructors:
- Parameterized constructor
- Non parameterized constructor
- Default constructor
4. Constructor does not return anything not even void, it return only and only one thing
i.e. the instance of a class.
5. Constructor is always public.
6. Constructor is always invoked when you create object of a class.
7. You can call one constructor from another constructor inside the same class for this,
this should be the first statement inside the constructor .
8. If you do not create ant constructor inside your class then JVM (java virtual machine)
will provide you a default constructor automatically which will provide you a default
constructor automatically which will be invisible to the programmer.
9. The syntax of default constructor is mentioned below:
public class Name()
{
super();
}
10. Super inside the constructor is used to call the base constructor.
11. Like method overloading is there is same way we can have constructor over loading.
12. We can write super braces this (); only once.
13. Constructor chaining is possible in java and it ends when it reaches the top most
class in java i.e., object class and that object class is responsible for returning the
instance of my class.
14. Recursive calling of constructor is not possible in java.