Data Abstraction in Java
Introduction :-In this post learn discuss on what is data abstraction why is important where is use and how to work in java so let's go start now. Data Abstraction means that Data Hidden. (Means that initial data is show and outside data is Hidden)
What is Data- Abstraction?
1.Abstraction Means Data Hiding, In other word we can say that in this type of Programming methods essential data is shown to the user or outside class and unessential data is hidden.
2.Members defined with a public access specifiers are access thorough the Program.
3.Members defined with a private access specifiers are not accessible thorough the program Means that private elements of a class can be accessed only inside the in this own class.
Where is use-
Where is use let's see an example : An AC(Alternating Current) which can be turned ON, OFF or change the any temperature change the Mode, and other external component such as FAN, Switch of Board, we don't known how it works in the external area details of AC any other Devices,
So we can say that finally AC is work on Data Abstraction type then we can create a Automatic Devices these types(Robots) perform your work AOTOMATIC.
Now we can say that again in Data Abstraction Cases how it works internally not matter , AC separates the implementation details from the external interfaces.
An Another Example:- Let's take a real life example assume that you are going a buying a car in a showroom then you can know about company name, model name, color, cost, and oil, type but you don't know about piston who made that model of car.
For better understanding see an example through program.
-----------------------------------------------------------------------------------------------------------------------------
class Showroom{
public void company(){
System.out.println("Renault");
}
public void model(){
System.out.println("Duster");
}
public void color(){
System.out.println("White/ Gray/ Blue / Yellow / Black");
}
public void oil(){
System.out.println("Petrol");
}
public void price(){
System.out.println("8 lakhs, 10 Lakhs, 12 Lakhs/ 14 Lakhs");
}
private void made_name(){
System.out.println("Alex Remon");
}
private void piston(){
System.out.println("5 Piston");
}
public static void main(String args[]){
Showroom obj= new Showroom();
// This is all public accessfiers can be access any where in the program
System.out.println("\n \n Public Proparetry Show Feturea of Car ");
obj.company();
obj.model();
obj.color();
obj.oil();
obj.price();
// Now used private modifiers can be access only inside of claas
System.out.println(" \n \n Private Proparerty Show only Adimstrator ");
// obj.made_name();
// obj.piston();
}
}
Advantage of Data Abstraction
- We can provide security of data using Abstraction.
- Data Abstraction avoids code duplication and increase the code reusability.
- We don't have to write the low-level code because private elements of a class.
I HOPE THIS IS HELPFUL FOR YOU THANK YOU.
Comments