Consider the variable state in the class Door and the variab

Consider the variable state in the class Door and the variable new State in the matador for state. What kind of variable is state? What kind of variable is new State? When do these variables exist?

Solution

We have 3 types of Variables, the 3 types are: -

The definition of the above Variables is given below: -

Instance Variables: - Instance Variables are Variables which are declared inside a class, but outside a method, and these variables can be accessed anywhere in the class.

Static Variables: - Static Variables are Variables which are declared same as Instance Variables, but have a fixed Value, and can be accessed anywhere in the Class.

Local Variables: - Local Variables are variables which are declared inside a method, and can only be used in the method itself where they are declared, nowhere else.

Now according to the given question, we have a class door, and a Variable state in it, and a variable new state as the mutator for state

Mutator refers to a method which is used to change/alter the value of an Instance Variable.

So, the Conclusion is, state is an Instance Variable and new state is an local Variable, having the definitions given above.

state- Instance Variable

new state- Local Variable

This is all for the question

Thank You for using Chegg...

 Consider the variable state in the class Door and the variable new State in the matador for state. What kind of variable is state? What kind of variable is new

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site