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();
} }