What is Abstraction?

1 answers

Abstraction is the process of separating ideas from specific instances and thus, develop classes in terms of their own functionality, instead of their implementation details. Java supports the creation and existence of abstract classes that expose interfaces, without including the actual implementation of all methods. The abstraction technique aims to separate the implementation details of a class from its behavior.

public abstract class Person  { 

public abstract String getName();

}

Employee class extends the Abstract class Person. The method getName returns the name attribute of the employee.

public class Employee extends Person { 

private String name;

public Employee(String name){

this.name = name;

}

public String getName(){

return this.name;

}

public static void main (String args[]) { 

Employee employee = new Employee("John Wilson");

System.out.println("Employee's Name "+ employee.getName());

Person person = new Employee("Thomas Smith");

System.out.println("Employee-Person's Name "+ person.getName());

}

shilpigupta22 shilpigupta22 [Author] 4 months ago votes 0