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

What does three dots mean in java?

1116


Are strings immutable in java?

969


How do you escape in java?

1061


Is 64bit faster than 32 bit?

1065


Can we overload the constructors?

986


What is getclass () getname () in java?

1137


What are the advantages of arraylist over arrays?

1084


How to run a JAR file through command prompt?

1266


What is the similarity between dynamic binding and linking?

1114


Can you inherit from an abstract class java?

985


What do you mean by chromounits in java8?

944


What is the advantage of preparedstatement over statement?

1098


Highest level event class of the event-delegation model?

4001


Can we use string in switch case in java?

1045


How many types of memory areas are allocated by jvm?

1032