Showing posts with label Constructor. Show all posts
Showing posts with label Constructor. Show all posts

Constructor in Java /Chapter -12 /OOPs Concept

java constructorjava constructor


Whenever we are creating an object some part of the java program(code) will be executed automatically to perform initialization of the object, this part of the program is called "Constructor".
Hence the main objective of the constructor is to perform initialization of an object. 

example 1.

class Employee

{

String name;

int eid;

Employee (String name, int eid)

{

this.name = name;

this.eid = eid;

System.out.println(name+"-----"+eid);

}

public static void main(String args[ ])

{

Employee e1 = new Employee("Dhoni",101);

Employee e2 = new Employee("Virat",102);

}

}

Output of the above program is:-

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com