0
Can't get the output while using Constructor method.
An output error is: color(attribute) has private access in Vehicle(class) ! https://code.sololearn.com/crh6nPW406l4/?ref=app
4 Respuestas
0
Zulqarnain Khan
You cannot access private members directly using class object. Make setter getter then access value of color. That's called incapsulation.
+ 1
Now let me clear that,
...
Constractors are used for initialization with already created objects, and can also be used to provide initial value for objects attribute(variable).
Thanks in advance! :)
0
Then what is the main purpose of Constructors at all !
0
Zulqarnain Khan
Constructor is used to initialise value and object not to access class members.
As you have created parameterized constructor and passed value so it will change the original value of color.
But if you want to access class members directly using class objects then make public.