Ad Code

PublicTranport and PrivateTranport are subclasses of Transport.Car and Bike are sub-classes or derived classes of PrivateTransport .PMT and Auto are sub-classes or derived classes of Public Transport.Assume sutaible mehods and veriables

class Transport{
String name;
Transport(String name){
this.name = name;
}
}
class PublicTransport extends Transport{
int capacity;
PublicTransport(int c, String name){
super(name);
this.capacity = c;
}
void publicTransport() {
System.out.println(super.name+" can carry many passengers");
}
}
class PrivateTransport extends Transport{
int capacity;
PrivateTransport(int c, String name){
super(name);
this.capacity = c;
}
void privateTransport() {
System.out.println(super.name+" can carry less passengers");
}
}
class PMT extends PublicTransport{
PMT(){
super(30,"PMT");
}
public void capacity() {
System.out.println("PMT capacity is "+capacity);
}
}
class Auto extends PublicTransport{
Auto(){
super(4,"Auto");
}
public void capacity() {
System.out.println("Auto capacity is "+super.capacity);
}
}
class Car extends PrivateTransport{
Car(){
super(6,"Car");
}
public void capacity() {
System.out.println("Car capacity is "+super.capacity);
}
}
class Bike extends PrivateTransport{
Bike(){
super(2,"Bike");
}
public void capacity() {
System.out.println("Bike capacity is "+super.capacity);
}
}
public class travel {
public static void main(String[] args) {
Car c = new Car();
c.capacity();
Bike b = new Bike();
b.capacity();
PMT p = new PMT();
p.capacity();
Auto a = new Auto();
a.capacity();
}
}

Reactions

Post a Comment

0 Comments