ㅤㅤ

What are Abstract methods in Java ? | Abstract Class in Java and Methods

Abstract Class in Java and Methods | What are Abstract methods in Java ? 

What are Abstract methods in Java ? | Abstract Class in Java and Methods

What are Abstract methods?

Abstract class can contain abstract methods. Abstract methods do not have implementation. Abstract methods should be implemented in the subclasses which inherit them. So if an abstract class has an abstract method class inheriting the abstract class should implement the method or else java compiler will through an error.

 In this way, an abstract class can define a complete programming interface thereby providing its subclasses with the method declarations for all of the methods necessary to implement that programming interface. Abstract methods are defined using "abstract" keyword. Below is a sample code snippet.

abstract claas myAbstract Graphics

abstract void draw();

Any class inheriting from "myAbstractGrpahics" class should implement the "dras" method or else the java compiler will throw an error.

What is the difference between an interface and abstract class

(B) What's the difference between "Abstract" classes and "Interfaces"?

Difference between Abstract class and Interface is as follows: Abstract class can only be inherited while interfaces can not be it has to be, implemented

V Interface cannot implement any methods, whereas an abstract class can have implementation. Class can implement many interfaces but can have only one super class.

Interface is not part of the class hierarchy while Abstract class comes in through inheritance. Unrelated classes can implement the same interface.

What are Abstract methods in Java ? | Abstract Class in Java and Methods

Post a Comment

Thanks for Comment

Previous Post Next Post