0
why value of a is not overiding??
class see int a; main () see x = new see(); see y = new see(); x.a= 4; y.a=5; syso(x.a). ==4 syso(y.a ) ==5 why variable a have two values?
7 Réponses
+ 6
You can see a class as a factory that produces objects.
Your class See might produce glasses with the attribute a, which could be a int number that stands for the color or something.
No you create two objects, glasses x and glasses y. Two different glasses. Each of that object can have it's own value for the color which is stored in the attribute a.
Your object x can be blue (x.a) and your object y can be red (y.a). Although their type (class See) is the same.
And if you paint your x object black, your y object still remains red.
Hope this example can help you.
+ 4
No, imagine it like: a is for color. You can produce with which color value you like, blue or red. And you can change it after production (under certain circumstances - attribute must be accessible somehow).
+ 4
Just what I said ^^
It may have the color *whatever*. And another object can have another color. Do you agree that cars can have different colors although they are produced in the same factory?
+ 4
Replace object by attribute and you're on the right way ;)
+ 1
no I don't understand, let's say a is for blue color and see produce class then two blue glass will be created
thanks in advance Tashi N
0
but a is type color and has value green
0
okey!now I understand here car body is "a "and color is object i.e. x and y.right?