0% found this document useful (0 votes)
12 views2 pages

Polymorph Demo Java

The document describes a program that implements a vehicle class hierarchy to demonstrate polymorphism. The program defines vehicle, car, and lorry classes with registration number and model attributes. The car and lorry classes extend the vehicle class and override the print method to output vehicle details in a polymorphic manner.

Uploaded by

Praveen Pravi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Polymorph Demo Java

The document describes a program that implements a vehicle class hierarchy to demonstrate polymorphism. The program defines vehicle, car, and lorry classes with registration number and model attributes. The car and lorry classes extend the vehicle class and override the print method to output vehicle details in a polymorphic manner.

Uploaded by

Praveen Pravi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM:

/**
* This program is written to implement vehicle class hierarchy and demonstrate polymorphism
* @author Praveen.K 22908104028
* @version 1.0
*/
import java.io.*;

class vehicle

String regno;

int model;

vehicle(String r,int m)

regno=r;

model=m;

void print()

System.out.println("registration no: "+regno);

System.out.println("Model: "+model);

class car extends vehicle

int no_of_wheel;

car(String r,int m,int n)

super(r,m);

no_of_wheel=n;

void print()
{

System.out.println("car");

super.print();

System.out.println("no of wheels: "+no_of_wheel);

class lorry extends vehicle

int no_of_wheel;

lorry(String r,int m,int n)

super(r,m);

no_of_wheel=n;

void print()

System.out.println("Lorry");

super.print();

System.out.println("no of wheels: "+no_of_wheel);

public class polymorphDemo

public static void main(String args[])

car c=new car("PY 29 K 4328",1,4);

lorry l=new lorry("TN 90 B 1901",4,4);

c.print();

l.print();

} }

You might also like