Friday, 21 September 2012

Java Practical - 11



    Program Definition 11 ::
 
     The abstract Airplane class has three subclasses named B747, B757 and B767.  Each airplane type can transport a different number of passengers.  Each airplane object has a unique serial number.  Write an application that declares class hierarchy.  Instantiate several types of airplanes and display them.  Override the toString() method of Object to return a string with the type, serial number and capacity..





abstract class Airplane
{
protected int serialNumber;
protected int passengerCapacity;
protected String name;
Airplane(int sn, String nm ,int pc)
{
serialNumber = sn ;
name = nm ;
passengerCapacity = pc ;
}

public String toString()
{
return "serial number : " + serialNumber + "  \n passenger capacity : " +

passengerCapacity + " \n  name : " + name;

}
}


class B747 extends Airplane
{

B747(int sn , String nm, int pc)
{
super(sn , nm,  pc);
}
}

class B757 extends Airplane
{
B757(int sn , String nm, int pc)
{
super(sn , nm,  pc);
}
}

class B767 extends Airplane
{
B767(int sn , String nm , int pc)
{
super(sn ,nm,  pc);
}
}

class TestAirplane
{
public static void main(String args[])
{
System.out.println(" Program 11");

B747 b1 = new B747(001,"Boying", 450);
B757 b2 = new B757(101,"Airbus", 750);

System.out.println(b1.toString());
System.out.println(b2.toString());

}
}

/*
D:\JAVA >javac Prog11.java

D:\JAVA >java TestAirplane
 Program 11
serial number : 1
 passenger capacity : 450
  name : Boying

serial number : 101
 passenger capacity : 750
  name : Airbus
*/





Kindly Bookmark and Share it:

0 comments :

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT