what is interface and Abstract class in java

what is Interface in java & how it is related to Abstract class or abstract keyword. please tell me in detail

  • Rahul Kumar
  • 07 Nov
  • 2053 Views
  • 5 Answers

5 Answers
  • interface are implicitly abstract and cannot have implementations. A Java abstract classcan have instance methods that implements a default behavior. An abstract class may contain non-final variables. Members of aJava interface are public by default

  • A java class can implement java interface .it is necessary that the class must implement all the methods declared in the interfaces .the interface allows sending a message to an object without concerning which classes it belongs . An interface is a reference type in java .it is similar to class .it is collection of abstract methods .a class implements an interface ,by inheriting the abstract methods of the interface .along with abstract methods ,an interface may also contains ,default methods ,static methods and nested types . An abstract class is an context of java ,is a superclass that cannot be instantiated and is used to state or define general characteristics. An object cannot be formed from java abstract class trying to instantiate an abstract class only produces a compiler error.

  • An interface in java is a blueprint of a class. It has static constants and abstract methods
    A class which is declared as abstract is known as an abstract class. It can have abstract and non-abstract methods. It needs to be extended and its method implemented. It cannot be instantiated.

  • The Interface is a blue print that can be used to implement a class.The  Interface does not contain any methods that have code. All the methods of an interface are abstract methods.
    A class which has the abstract keyword in its declaration is called Abstract class. Abstract classes should have atleast one abstract method ie.,. methods without a body. 

  • Let's generalize the concept abstract class is something like a combination of both classes and interfaces means in abstract class we may have normal methods, variables.But interface is a collection of abstract methods only method signature is given in interface.

Did Not Get The Answer? 
Contact people of Talent-Core Java directly from here

Core Java