Social Icons

Wednesday, 4 September 2013

Dynamic Dispatch With abstract Function

abstract class A
{
int d1;
int d2;

abstract double area();

 A(int a, int b)
{
d1=a;
d2=b;

}

}


class B extends A
{
  B(int a,int b)
  {
  super(a,b);
  }

  double area()
  {
   return (d1*d2);
  }


}




class C extends A
{
 C(int a, int b)
 {
  super(a,b);
 }

 double area()
{
return d1*d2;
}

}

class over
{
public static void main(String args[])
{
C c=new C(5,3);
B b=new B(4,5);
A r;
r=c;
System.out.println(r.area());
r=b;
System.out.println(r.area());

}
}

No comments:

Post a Comment

 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management