abstract class Vegetable
{
String color;
abstract String tostring();
}
class Cabbage extends Vegetable
{
String tostring()
{
color = "green";
return "cabbage color: "+color;
}
}
class Carrot extends Vegetable
{
String tostring()
{
color = "red";
return "carrot color: "+color;
}
}
class Patato extends Vegetable
{
String tostring()
{
color = "yellow";
return "patato color: "+color;
}
}
class Program10
{
public static void main(String args[])
{
Cabbage obj1 = new Cabbage();
Carrot obj2 = new Carrot();
Patato obj3 = new Patato();
System.out.println(obj1.tostring());
System.out.println(obj2.tostring());
System.out.println(obj3.tostring());
}
}
No comments:
Post a Comment