Difference between Encapsulation and Abstraction

Answer Posted / balbir

encapsulation:wraping of data and method into single unit.
e.g:

public class Test {
private int id;
private int roll;

public void method(int i,int j){
id = i;
roll = j;
System.out.println("===id==="+id);
System.out.println("===roll==="+roll);
}
public static void main(String args[])
{
Test t =new Test();
t.method(100,200);
}
}

in above example privatevariable wrap with public
method,this is encapsulation.

Abstraction:hiding the implementation details from the
external users.
e.g: electric switch board is available for end user
without knowing the implementation details.means end user
not bother about what is the manufactored items inside th
switch board.this is called abstraction.

Is This Answer Correct ?    12 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

when to use ArrayList and when to use HashMap in webApplication.

4225


Can we have a try block without catch block?

752


What is the main functionality of the remote reference layer?

1640


Define how destructors are defined in java?

763


What is the current version of java?

758


What is collection class in java? List down its methods and interfaces.

721


Write a program to find the whether a number is an Armstrong number or not?

776


What is a Transient Object?

826


What is the meaning of 3 dots in java?

876


Can we declare a class as abstract without having any abstract method?

763


Can inner class be public in java?

740


What is a protected class in java?

751


What is the use of default method in interface in java?

759


Why is string class considered immutable?

804


What is the difference between the file and randomaccessfile classes?

799