Abstraction

0
9

Abstraction

Abstraction in Java is used to hide certain details and only show the essential features of the object. In other words, it deals with the outside view of an object (interface).

An abstract class contains an abstract keyword. An abstract class can or cannot have abstract methods.

A method that is declared as abstract and does not have implementation is known as abstract method.

Example:

An abstract class with abstract method:-

  1. abstract class Fan
  2. {
  3. abstract void run();
  4. }
  5.  
  6. class Havells extends Fan
  7. {
  8. void run()
  9. {
  10. System.out.println("Good speed");
  11. }
  12.  
  13. public static void main(String args[])
  14. {
  15. Fan obj = new Havells();
  16. obj.run();
  17. }
  18. }

Output:

Good speed

Facebook Comments
(Visited 14 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here