package A;
public class Car
{
//protected
protected String maker;
//public
public Car(String maker)
{
this.maker = maker;
}
//package-private
String getMaker()
{
return maker;
}
}
package B;
import A.Car;
public class Buick extends Car
{
protected String color;
public Buick(String m, String c)
{
super(m);
color = c;
}
public String getColor()
{
return color;
}
public String toString()
{
return maker+" "+color;
}
}
package C;
import B.Buick;
public class Rendezvous extends Buick
{
private int year;
public Rendezvous(String m, String c, int y)
{
super(m, c);
year = y;
}
public String toString()
{
return maker+" "+color+" "+year;
}
}
import A.Car;
import B.Buick;
import C.Rendezvous;
public class CarTest
{
public static void main(String args[])
{
Car c = new Car("Buick");
Buick b = new Buick("Buick", "White");
Rendezvous r = new Rendezvous("Buick", "White", 2005);
System.out.println(r);
}
}
package A;
public class Car
{
//protected
protected String maker;
//public
public Car(String maker)
{
this.maker = maker;
}
public String getMaker()
{
return maker;
}
@Override
public String toString()
{
return "Car: "+maker;
}
}
package B;
import A.Car;
public class Buick extends Car
{
protected String color;
public Buick(String m, String c)
{
super(m);
color = c;
}
public String getColor()
{
return color;
}
@Override
public String toString()
{
//call it's parent's toString
return "Buick: "+ super.toString()+" "+color;
}
}
import A.Car;
import B.Buick;
public class CarTest
{
public static void main(String args[])
{
Car c = new Car("Buick");
Buick b = new Buick("Buick", "White");
System.out.println(c);//toString of Car is called
System.out.println(b);//toString of Buick is called
System.out.println(b.getMaker()+" "+b.getColor());
}
}
public class Car
{
public static void display()
{
System.out.println("Car");
}
}
public class Buick extends Car
{
public static void display()
{
System.out.println("Buick");
}
}
public class CarTest
{
public static void main(String args[])
{
Car c = new Car();
Buick b = new Buick();
c.display();//Car
b.display();//Buick
}
}