Thursday, August 1, 2013

PROGRAM FOR MULTIPLE INHERITANCE

PROGRAM:
~~~~~~~~~
sports.java
interface sports    //Interface declaration
{
float sportwt=6.0F;
void putwt();
}

test.java
public class test                 //Class declaration
{
float p1,p2;
void getmarks(float m1, float m2)
{
p1=m1;
p2=m2;
}
void putmarks()
{
System.out.println("Marks obtained is ");
System.out.println("Part1 = "+p1);
System.out.println("Part2 = "+p2);
}
}

results.java

public class results extends test implements sports           //Implementing Interface sports
{
float total;
public void putwt()                                             //Implementing abstract function of sports interface
{
System.out.println("Sports wt = "+sportwt);
}

void display()
{
total=p1+p2+sportwt;
putmarks();
putwt();
System.out.println("total score = "+total);
}
}

multi.java

public class multi 
{
public static void main(String[] args) 
{
results ob= new results();
ob.getmarks(23.6F,33.0F);
ob.display();
}

}

NOTE:
TRY TO EXECUTE THIS PROGRAM WITH ECLIPSE IDE.

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips