0% found this document useful (0 votes)
6 views8 pages

Hierarchical Inheritance

The document contains Java code defining a class hierarchy for vehicles, including base class 'Vehicle' and derived classes 'TwoWheeler', 'ThreeWheeler', and 'FourWheeler'. Each class has methods to accept and display vehicle details, such as company name, color, and specific attributes like bike name and cost. The 'main' method demonstrates creating instances of each vehicle type and invoking their respective methods to show their details.

Uploaded by

dakshini742006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

Hierarchical Inheritance

The document contains Java code defining a class hierarchy for vehicles, including base class 'Vehicle' and derived classes 'TwoWheeler', 'ThreeWheeler', and 'FourWheeler'. Each class has methods to accept and display vehicle details, such as company name, color, and specific attributes like bike name and cost. The 'main' method demonstrates creating instances of each vehicle type and invoking their respective methods to show their details.

Uploaded by

dakshini742006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

class Vehicle

String cname,clr;

void accept(String
cn,String c)
{
cname=cn;
clr=c;
}

void display()
{

[Link]("The name of
Company is"+cname);
[Link]("The color of
vehicle is"+clr);
}

class TwoWheeler extends


Vehicle
{
String bname;
long cost;

void get(String b,long


c)
{
bname=b;
cost=c;
}
void put()
{
[Link]("The name of Bike
is"+bname);

[Link]("The Cost of bike


is"+cost);
}

class ThreeWheeler extends


Vehicle
{

String tname;
long cost;

void input(String
tn,long c)
{
tname=tn;
cost=c;
}
void output()
{

[Link]("The name of three


wheeler is"+tname);

[Link]("The cost of three


wheeler is"+cost);
}

class FourWheeler extends


Vehicle
{

String fname;
long price;
void getdata(String
fn,long p)
{
fname=fn;
price=p;
}

void putdata()
{

[Link]("The name of four


wheeler is"+fname);

[Link]("The Price of four


wheeler is"+price);
}

}
class Tree
{

public static void


main(String[] args)
{

Vehicle v=new
Vehicle();
TwoWheeler
tw=new TwoWheeler();
ThreeWheeler
th=new ThreeWheeler();
FourWheeler
fw=new FourWheeler();

[Link]("Honda","White");
[Link]();

[Link]("Activa
125",98000);
[Link]();

[Link]("Bajaj","Yellow");
[Link]();

[Link]("Auto",230000);
[Link]();

[Link]("Toyota","Black");
[Link]();

[Link]("Fortuner",3500000);
[Link]();

}
}

You might also like