Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to access a variable if it is declared as private?

Answer Posted / ranganathkini

If a variable inside a class is marked private then it
cannot be accessed directly.

Access to this variable can only be provided by a public
accessor and mutator methods. Example:

class MyClass {
private int dataValue;

public int getDataValue {
return dataValue;
}

public void setDataValue( int newValue ) {
dataValue = newValue;
}
}

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When should I use stringbuffer?

1056


Explain the use of shift operator in java. Can you give some examples?

1035


Can we split string with in java?

1073


What are the differences between throw and throws?

1106


What is the technique adopted to create an immutable class?

1189


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

1043


Explain the difference between serializable and externalizable in java?

1136


What is a private class in java?

1121


What is compareto?

1104


What is the difference between notify and notifyall method?

1313


Can we override constructors?

1050


What does indexof mean?

1105


How do you check if an arraylist is not empty?

1187


What does yield method of the thread class do?

1083


What are the advantages of functions?

955