You are on page 1of 2

Abstraction - Hiding the implementation

Abstract class - have both abstract methods and non abstract methods

Abstract methods- method without implementation

Interface is similar to class

Interface - class contruct that have only constants and abstract methods

pure abstraction --->interface


Java class

modifier class classname


{
int var;
void method()
{

}
}
modifier - public /private/protected/default

structure of interface

public interface geometricobject


{
int a=1; // constants
public void draw(); // abstract method
}

CONSTANTS in interface -> public static final

METHODS in interface -> abstract

ABSTRACT CLASS cannot be instantiated


Interface cannot be instantiated

implements - keyword for inheriting class-interface

extends -keyword for inheirting class-class


keyword for inheirting interface-interface

Simple inheritance
using Interface

hierarchical inheritance using interface

Interface geometricobject
---> variable type
---> method draw()
Class circle implements geometricobject

class rectangle implements geometricobject

Test the functionality

multilevel inheritance using Interface

when you have to use interface

1)Pure abstraction
2)Achieve multiple inheritance
3)resolve ambiguity problem arising from multiple inheritance

You might also like