answersLogoWhite

0


Best Answer

I see no reason why you can't do that. The question must be mis stated. Please clarify, and show your code.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why you cant initialise a value of a variable inside public in class in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is class variable?

Class Variables or Instances variables are variables that are declared inside a class and are available for the whole class. They are available for all instances of that class and are not specific to any method. Ex: public class Test { private String name = "Rocky"; } Here name is a class variable.


What is member variable in java?

We use the term member variable to refer to variables that are defined inside a method. Ex: public String getName(){ String x = "ttt"; ..... } In the method getName() x is a member variable


What is static variable in the class for c plus plus?

Static member variables are local to the class. That is, there is only one instance of a static member variable, regardless of how many objects are instantiated from the class. As such, they must be declared inside the class, and defined outside of the class.


What is the application of public protected and private keywords?

The public, protected, and private keywords are access modifiers that specify if the item they modify can be accessed inside or outside the class or a derived class.A public item is fully accessible, inside or outside the class, including inside a derived class.A protected item is accessible only inside the class or inside a derived class.A private item is accessible only inside the class.


How do you access private variable in flex?

In Flex, you access a private variable by calling it from within that class. Remember, the "private" modifier means it cannot be directly accessed outside of the class you declare it in (note I say "directly accessed" you can indirectly access it via public functions which I will show below). Example: declare your variable at the top of your class like this: private var myVariable:String; Then, inside one of your functions of that class, you can access the variable and/or assign it this way: public function changeMyVariable(value:String):void { // sets the private variable to a custom string myVariable="test String"; trace("myVariable is set to "+myVariable); // sets the private variable to the argument passed in myVariable = value; trace("myVariable is now set to" +myVariable); }

Related questions

What is class variable?

Class Variables or Instances variables are variables that are declared inside a class and are available for the whole class. They are available for all instances of that class and are not specific to any method. Ex: public class Test { private String name = "Rocky"; } Here name is a class variable.


Which is public to all access class or struct or function or variable?

The default access specifier for a class is private. The default access specifier for a struct is public. It does not matter if it is a function or a variable.


What is member variable in java?

We use the term member variable to refer to variables that are defined inside a method. Ex: public String getName(){ String x = "ttt"; ..... } In the method getName() x is a member variable


What is static variable in the class for c plus plus?

Static member variables are local to the class. That is, there is only one instance of a static member variable, regardless of how many objects are instantiated from the class. As such, they must be declared inside the class, and defined outside of the class.


How do you access private variable in flex?

In Flex, you access a private variable by calling it from within that class. Remember, the "private" modifier means it cannot be directly accessed outside of the class you declare it in (note I say "directly accessed" you can indirectly access it via public functions which I will show below). Example: declare your variable at the top of your class like this: private var myVariable:String; Then, inside one of your functions of that class, you can access the variable and/or assign it this way: public function changeMyVariable(value:String):void { // sets the private variable to a custom string myVariable="test String"; trace("myVariable is set to "+myVariable); // sets the private variable to the argument passed in myVariable = value; trace("myVariable is now set to" +myVariable); }


What is the application of public protected and private keywords?

The public, protected, and private keywords are access modifiers that specify if the item they modify can be accessed inside or outside the class or a derived class.A public item is fully accessible, inside or outside the class, including inside a derived class.A protected item is accessible only inside the class or inside a derived class.A private item is accessible only inside the class.


what type of variable is visible to every module and the entire program?

If you are talking about a class in Java, a variable encapsulated by a class is called an instance variable b/c everytime you create an object with that class, each object has its own set of the variables declared.


What is public static final variable in java?

-Public to all - Static to access with Class Name - Final to change( constant and not alowed to change) Just use it along with class name. (As implied above, a 'public static final' variable in Java is what other languages would call a Constant. )


What does In public mean?

The keyword public is an access specifier. A variable or a method that is declared public is publicly accessible to any member of the project. Any class or method can freely access other public methods and variables of another class.


What is the scope of any variable?

The Scope of a variable defines the areas of a program where this variable would be visible and can be used. For ex: a. Method variables - are visible only inside the method where they are declared and hence their scope is only the method b. Class variables - are visible inside the class and can be used by any method inside the class and hence their scope is the whole class.


What does a Java Boolean type variable declared but not yet initialized contain when its class is instanciated?

If it is a class or instance variable, it gets the default value of false. If it is a local variable (inside a method), it doesn't have a value until you explicitly set one.


Describe about storage allocation and scope of global extern static local and register variables?

Global Varible: The variable which is declared as "Global" one : having the preveleges to use and access that variable in any class and object( means any where in the program) just like PUBLIC keyword in OOPS concepts. Static Variable : If we declare a variable as Static , then it wont have the permission to access that variable through out the program and u have to use it inside the class or object which u declared itself. All the Best Annapurna