Abstraction concept seems to like hiding data from outside world.
" Hiding internal implementation and just highlight the set of services what we are offering to the outside world" its Abstraction.
Abstraction is achieved by using interface and abstract class. interface gives 100% abstraction.
Example : When we go to the ATM. there we can see only GUI screen. bank management highlights the set of services like cash withdrawal, balance inquiry etc but we do not know what are the process is done internally. they highlight services only without sharing internal implementation.
Advantage :
1.It provides security for application.
2.Enhancement is easy.
3.It improves maintainability of the application
4.It improves easiness to use.
package example;
class Employee extends Person {
private String empCode;
public String getEmpCode() {
return empCode;
}
public void setEmpCode(String empCode) {
this.empCode = empCode;
}
}
abstract class Person {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Main{
public static void main(String args[]){
//INSTIATING AN ABSTRACT CLASS GIVES COMPILE TIME ERROR
//Person p = new Person() ;
//THIS REFERENCE VARIABLE CAN ACESS ONLY THOSE METHOD WHICH ARE OVERRIDDEN
Person person = new Employee();
person.setName("Indrajeet Singh");
System.out.println(person.getName());
}
}
<< >>
" Hiding internal implementation and just highlight the set of services what we are offering to the outside world" its Abstraction.
Abstraction is achieved by using interface and abstract class. interface gives 100% abstraction.
Example : When we go to the ATM. there we can see only GUI screen. bank management highlights the set of services like cash withdrawal, balance inquiry etc but we do not know what are the process is done internally. they highlight services only without sharing internal implementation.
Advantage :
1.It provides security for application.
2.Enhancement is easy.
3.It improves maintainability of the application
4.It improves easiness to use.
package example;
class Employee extends Person {
private String empCode;
public String getEmpCode() {
return empCode;
}
public void setEmpCode(String empCode) {
this.empCode = empCode;
}
}
abstract class Person {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Main{
public static void main(String args[]){
//INSTIATING AN ABSTRACT CLASS GIVES COMPILE TIME ERROR
//Person p = new Person() ;
//THIS REFERENCE VARIABLE CAN ACESS ONLY THOSE METHOD WHICH ARE OVERRIDDEN
Person person = new Employee();
person.setName("Indrajeet Singh");
System.out.println(person.getName());
}
}
<< >>