//Program to demonstrate multiple Inheritence
//Program by Ahlam Ansari
interface Area
{
final static float pi=3.14F;
float compute();
}
class Shape
{
public String display()
{
return("Calculating the area of CIRCLE....");
}
}
class Circle extends Shape implements Area
{
float radius;
Circle(float x)
{
radius = x;
}
public float compute()
{
return (pi*radius*radius);
}
}
class MultipleLevel
{
public static void main(String ahlam[])
{
Circle c=new Circle(10.0f);
Area ar=c;
System.out.println(c.display() + "\n " + ar.compute()+" square.cm");
}
}
/*
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>javac MultipleLevel.java
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>java MultipleLevel
Calculating the area of CIRCLE....
314.0 square.cm
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>
*/
//Program by Ahlam Ansari
interface Area
{
final static float pi=3.14F;
float compute();
}
class Shape
{
public String display()
{
return("Calculating the area of CIRCLE....");
}
}
class Circle extends Shape implements Area
{
float radius;
Circle(float x)
{
radius = x;
}
public float compute()
{
return (pi*radius*radius);
}
}
class MultipleLevel
{
public static void main(String ahlam[])
{
Circle c=new Circle(10.0f);
Area ar=c;
System.out.println(c.display() + "\n " + ar.compute()+" square.cm");
}
}
/*
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>javac MultipleLevel.java
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>java MultipleLevel
Calculating the area of CIRCLE....
314.0 square.cm
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>
*/
No comments:
Post a Comment