Monday, 24 March 2014

ABSTRACT CLASSES IN JAVA

Posted By: Unknown - Monday, March 24, 2014

Abstract classes as name suggest that there is something abstract on it and it is not concrete. Abstract classes are partial implemented classes which have at least one method abstract. Super Class wants to instruct child class to implement this method in its own way. Abstract classes can have methods and varaiables. Methods can be abstract or non abstract but one method is supposed to be abstract. Until you provide definition of all parent methods abstract class in its child class, child class can not instantiated ( object can not be created ). Unlike Interfaces, child class can have not static & final variables. It is possible to extend abstract class but not implement its all abstract method. In this class, class is supposed to be abstract class.

Sample Example of Abstract Class :
abstract class SimpleCalculatorAbstract
{
   private String name = "SimpleCalculator";
   void setName( String nameOfCalcy )
   {
 name = nameOfCalcy;
   }
   String getCalcyName()
   {
  return name;
    }
    abstract  float add(float num1, float num2 );
    abstract  float substract(float num1, float num2 );
    abstract  float multiply(float num1, float num2 );
    abstract  float divide(float num1, float num2 );
}
As shown in example, Abstract have abstract methods and non abstract methods.
Now, In same way, I create one interface which will have all methods declared ( which is here abstract methods ).
interface SimpleCalculatorInter
{
    float add(float num1, float num2 );
    float substract(float num1, float num2 );
    float multiply(float num1, float num2 );
    float divide(float num1, float num2 );
}

0 comments:

Post a Comment

this blog is helpful or not

International

Auto News

Translate

Pages

Popular Posts

Popular Posts

Designed By Templatezy / Sb Game Hacker Apk / MyBloggerThemes