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

What is the difference between a switch statement and an if statement?

513


What is the use of StringTokenizer class?

607


difference between byte stream class and character stream class?

4081


What is the method in java?

593


Explain wait() method of object class ?

630






Write a program to solve producer consumer problem in java?

562


Can we have multiple classes in single file ?

599


How to split a string in java?

622


What is parsing and its types?

583


Mention some interfaces implemented by linked list in java.

536


Where import statement is used in a java program?

608


According to java operator precedence, which operator is considered to be with highest precedence?

599


What is an argument in java?

507


What is the collections api in java programming?

548


What do you understand by an io stream?

581