class Vehicle
{
String brand;
String color;
}
class Car extends Vehicle
{
int totalDoor;
}
class Bike extends Vehicle
{
int cc;
}
class Main
{
public static void main(String args[])
{
Car c1 = new Car();
// accessing property from class Vehicle
c1.brand = "Honda";
c1.color = "black";
// accessing property from class Car
c1.totalDoor = 4;
Bike b1 = new Bike();
// accessing property from class Vehicle
b1.brand = "TVS";
b1.color = "blue";
// accessing property from class Bike
b1.cc = 150;
System.out.println("Car data " + c1.brand + " " + c1.color + " "
+ c1.totalDoor);
System.out.println("Bike data " + b1.brand + " " + b1.color + " "
+ b1.cc);
}
}
Output:
Car data Honda black 4
Bike data TVS blue 150
{
String brand;
String color;
}
class Car extends Vehicle
{
int totalDoor;
}
class Bike extends Vehicle
{
int cc;
}
class Main
{
public static void main(String args[])
{
Car c1 = new Car();
// accessing property from class Vehicle
c1.brand = "Honda";
c1.color = "black";
// accessing property from class Car
c1.totalDoor = 4;
Bike b1 = new Bike();
// accessing property from class Vehicle
b1.brand = "TVS";
b1.color = "blue";
// accessing property from class Bike
b1.cc = 150;
System.out.println("Car data " + c1.brand + " " + c1.color + " "
+ c1.totalDoor);
System.out.println("Bike data " + b1.brand + " " + b1.color + " "
+ b1.cc);
}
}
Output:
Car data Honda black 4
Bike data TVS blue 150
No comments:
Post a Comment