top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why Information hiding is used and how Information hiding is implemented in Java ?

+2 votes
42 views
Why Information hiding is used and how Information hiding is implemented in Java ?
posted Dec 22, 2014 by Dominic

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

In order to avoid direct access of an attribute in a class, attributes are defined as private and use getter and setter to restrict the access of attributes in a class.

Example class is given below

public class Person {
private String FirstName;

public String getFirstName() 
{
    return FirstName;
}
public void setFirstName(String FirstName) 
{
    this.FirstName = FirstName;
  }   
}
answer Dec 24, 2014 by Karthick.c
Similar Questions
0 votes

There is a Java Virtual Machine completely implemented in Java called JPF. In other words, when you run a Java program within this machine, it's a JVM-within-a-JVM execution. Obviously, this uses a lot of resources and I was thinking of ways how that could be reduced.

An idea I have is to compile JPF with GCJ to native code, thereby resulting in only one JVM that is used when running a Java program within JPF.

Do you see any inherent limitations to this idea, i.e. reasons why it wouldn't work? I'm not a JVM expert so it's hard for me to see any obvious obstacles.

...