donaricano-btn

Constructor_2

- Constructor is a special type of method that is used to initialize the object

- Constructor is invoked at the time of object creation


1. Rule

1) Constructor name must be same as its class name

2) Constructor must have no explicit return type


2. Type of constructor

1) Default constructor

2) Parameterized constructor


3. Default Constructor

3_1. Example


- If there is no constructor in a class, compiler automatically creates a default constructor


3_2. What is the purpose of default constructor?

- Default constructor provides the default values to the object like 0, null, etc

 


4. Parameterized Constructor

4_1. Why use parameterized constructor?

- Parameterized constructor is used to provide different values to the distinct objects

 


5. Copy Constructor

- There are many ways to copy the values of one object into another in java

1) By constructor

2) By assigning the values of one object into another

3) By clone() method of Object class


5_1. Example

 

'Back-End > Java_1' 카테고리의 다른 글

[Java] This keyword - to refer current class instance variable  (0) 2016.08.05
[Java] Static_2  (0) 2016.07.26
[Java] Method Overloading  (0) 2016.07.25
[Java] Object and Class  (0) 2016.06.27
[Java] Java OOPs Concepts  (0) 2016.06.27
블로그 이미지

리딩리드

,