Java Program 3 – Constructor

Program

class Car{

    public Car(){
        System.out.println("Inside car..Constructor");
    }
    
    public void Car(){
        System.out.println("Inside car..Method");
    }
    
    public Car(String color){
        System.out.println("Inside car.." + color);
    }
    
    public void acceleration(){
        System.out.println("Car Acceleration");
    }

}

class TestCar{
    
    public static void main(String args[]){
        Car c1=new Car();
        c1.Car();
        Car c2=new Car("Red");
        c1.acceleration();
    }
}


Output

D:\a5518\day2>javac car.java

D:\a5518\day2>java TestCar
Inside car..Constructor
Inside car..Method
Inside car..Red
Car Acceleration

D:\a5518\day2>


 

You can leave a response, or trackback from your own site.

Leave a Reply