JAVA program demonstrate different types of constructors.
PROGRAM :
package
com.company;
public class Car
{
String carColor;
Car()
{
System.out.println("Default
Constructor of Car class called");
}
Car(String carColor)
{
this.carColor = carColor;
}
Car(Car ob)
{
carColor=ob.carColor;
}
public void disp()
{
System.out.println("Color of the
Car is : "+carColor);
}
public static void main(String[] args)
{
Car c1 = new Car();
Car c2 = new Car("Blue");
c2.disp();
Car c3 = new Car(c2);
c3.disp();
}
}
Labels: JAVA program Demonstrate different types of constructors.


0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home