Example of abstract class

/*WAP that create abstract class figure. Declare area method in this class. class Rectangle and Circle inherits  class Figure.Write the method in all class that prints the area of respective Figure.*/



 abstract class Ab
   {
   abstract   void area();
}
class Rectangle extends Ab
   {
        int l,b;
     void  area()
   {
      System.out.println("rectengle is="+(l*b));
   }
 }
class circule extends Ab
   {
        int r;
     void  area()
   {
      System.out.println("circule is="+(3.14*r*r));
   }
 }   
class Abdemo
{
public static void main()
  {
     Ab  s1 =new Rectangle();
    Ab  s2 =new circule();
         s1.area();
        s2.area();
}
     
}      

Comments

Popular posts from this blog

Write a java program to calculate gross salary & net salary taking the following data

WAP a program that illustrates interface inheritance. Create two interface p1 and p2 . create Interface p which extends p1 and p2 and then create interface p12 which extends p12. Each interface declare one constants and one method. Create class Q which implements p12 and define all the methods of interface which displays value of constants

WAP that create interface on that you declare one method interest(p,r,n) then create two class simple and compound that implements interest and find simple and compound interest.