Java Constructor
Java Constructor
======================================================
Types of constructor
1.Default constructor
2.parameterized constructor
==================================================================
Imp notes :
example
//Default Constructor
public Vehicle() {
//Parametrized Constructor
=======================================================================
System.out.println(fan2.fanName);
=========================================================================
Copy Constructor :
example--
// Copy constructor
public Books(Books book) {
this.title = book.title;
this.author = book.author;
this.price = book.price;
this.publicationYear = book.publicationYear;
------------------
}
==================================================
Constructor Overloading :
===================================================
Constructor chaining :
calling the one constructor from another constructor in the same class or its
superclass.
Usually we are using this to avoid code duplication and to ensure that common
initialization takes place.
this.title = title;
this.author = author;
this.price = price;
this.publicationYear = publicationYear;