DEV Community

Akash
Akash

Posted on

Abstraction in JAVA

  • Abstraction is the process of hiding internal implementation details and showing only essential Functionality.
  • Showing only necessary and hiding unwanted
  • If any single method in class is abstract then the whole class is known to be a abstract class
  • Object cannot be created in abstract class

=> Abstraction can be classified into two types

  • Abstract Class
  • Interface

1.Abstract Class

  • It cannot be instantiated
  • contains abstract methods
  • Abstract class is declared using the "abstract" keyword
  • Abstract class can contain both abstract and non-abstract methods 1.
public abstract class Netflix
{
public abstract void watchfifa();
public void dark(){
System.out.println("Crime Thriller-Dark");
}
public void peakyblinder()
{
System.out.println("Early 20's Gangster film ");
}
}
Enter fullscreen mode Exit fullscreen mode

2.

public class OTT extends Netflix
{
public static void main(String[]args)
{
OTT ott=new OTT();
ott.peakyblinder();
ott.dark();
ott.watchfifa();
}
public void watchfifa(){
System.out.println("Spain won world cup");
}
}
Enter fullscreen mode Exit fullscreen mode

OUTPUT:

Top comments (0)