Constructor
public class Car
{
String mod;
int price;
public Car (String mod)
{
mod=mod;
//price=price;
}
public Car (String mod, int price )
{
this.mod=mod;
this.price=price;
}
public static void main(String[] args)
{
Car c1=new Car("Constructor 1");
System.out.println(c1.mod);
Car c2=new Car ("Constructor 2",10000);
System.out.println(c2.mod+"---"+c2.price);
}
}
No comments:
Post a Comment