Tuesday 25 September 2012

Java Practical - 15



    Program Definition 15 ::
 
     Define one abstract class named Mammal.  Bear, Elephant, Horse and Lion are concrete classes which extends Mammal.  Define interface Vehicle which declares drive() method and this interface is implemented by the Elephant and Horse classes.  Write main() method which creates and initializes an array of four Mammal objects.  Call drive() method for each object which has implemented Vehicle interface.




interface Vhicle
{

public void drive();
}

class Mammel
{

}

class Bear extends Mammel
{


}

class Elephant extends Mammel implements Vhicle
{
public void drive()
{
System.out.println("Elephant Called");
}

}

class Horse extends Mammel implements Vhicle
{
public void drive()
{
System.out.println("Horses Called");
}
}

class Lion extends Mammel
{

}

class TestMammel
{
public static void main( String args[] )
{

Horse h = new Horse();
Elephant e = new Elephant();

h.drive();
e.drive();

}
}


/*

D:\JAVA >javac TestMammel.java

D:\JAVA >java TestMammel
Horse Called
Elephant Called
*/


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