Real Time sample code for Encapsulation and Abstraction.
where to use abstract and where to use specifies like
public private.

Answer Posted / ravikiran

Encapsulation & Abstraction:

The private variable declaration is abstration,and making
usage of getters and setters is encapsulation

private String name="";
private String school="";

public String getName()
{
return name;
}

public void setName(String name)
{
this.name=name;
}

When We use private when we want to restrict the access
within the class.

When we use public then the variable or method will be
accessible in all the locations

Is This Answer Correct ?    18 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How much ram can a 64 bit processor theoretically?

689


What is the base class of all exception classes?

828


What is the association?

775


What are java methods?

820


How many tetrahedral voids are there in bcc?

775


What is the protected method modifier?

801


Write a function for palindrome and factorial and explain?

873


What is default exception handling in java?

784


Is it possible to specify multiple jndi names when deploying an ejb?

792


What is the main purpose of serialization in java?

798


What is the generic function?

751


How can constructor chaining be done using this keyword?

959


Tell us something about set interface.

784


What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. Import java.net.* Versus import java.net.socket)?

896


Is there any way to skip finally block of exception even if some exception occurs in the exception block?

858