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
Explain about the select method with an example?
What is the relationship between class and object?
What are checked exceptions?
What are data types in programming?
Can a list be null in java?
What is immutability in java?
Why volatile is used in java?
Can we declare the static variables and methods in an abstract class?
How to make object serializable in java?
What does .equals do in java?
Which data type is a class in java?
Write the algorithm to check the number non-leaf nodes in a tree.
Can we declare a static variable inside a method?
Which is fastest collection in java?
What is class and object in java?