Interface
- Click here for complete interface explanation.
- Can have only unimplemented methods.
- Supports multiple inheritance
- Can have only static and final variables.
- Methods can’t be static.
- Interface can’t hold main method or constructor.
- Interface can’t extend/implement abstract class.
- Keyword ‘interface’ is used to declare.
- Interface can extend other interface. Even More than one interface also.
- Signature below
1 2 3 4 5 6 7 8 9 10 11 |
interface InterfaceDemo { public abstract void onSuccess(); public abstract void onFail(); } interface InterfaceDemo2 extends InterfaceDemo{ void onSuccess(); void onError(); } |
Abstract Class
- Click here for complete abstract class explanation.
- Can have implemented and unimplemented methods. Means can have both abstract and non-abstract methods.
- Doesn’t support multiple inheritance.
- This can have non-final, final, static and non-static variables.
- Methods can be static.
- Can hold main method or constructor.
- Abstract class can extend other ordinary class or abstract class.
- Keyword ‘abstract’ is used..
- Abstract class can extend at most only one class.
- Signature below
1 2 3 4 5 6 7 8 9 |
package technical.jungle.com.abstractdemo; public abstract class JungleSecond extends TechnicalJungleAbstract { abstract public int setValue(); public void display() { System.out.println("www.technicaljungle.com -> display()"); } } |
Thanks for following at Twitter, now I am able to look over Java before being examinated again. Nice website.
nerzul2: Thanks for your valuable comment. I appreciate it.