Saturday, May 30, 2015

abstract keyword


// Abstract keyword can be applied to classes and instance methods only.
// This means things incomplete or to be complete later.

// Abstract classes
// The class can be declared as abstract class using ' abstract ' keyword.
// But even if you not declared class as abstract, the can become abstract if there is at least one abstract method.
// Abstract class can have non abstract methods also.
// An abstract class can never be instantiated.
// We can't be created objects using abstract class.

// Abstract methods
// Abstract methods doesn't have a method body. It has only specification.The method body is provided by sub class.
// These methods can never be final and it can't be used private access modifier.
// The method declaration of this methods are different from other methods.


abstract class Demo {

public abstract void methodName();
public void methodName2() {}
}

----------------------------------------------------------------------------------------------------


public class Demo2 extends Demo{

public static void main(String[] args) {
Demo2 d2 = new Demo2();
d2.methodName();
}
@Override
public void methodName() {
System.out.println("MethodName by implementing the adbtract methods from \n"+"super           class Demo");
}

}


No comments:

Post a Comment