HI Paul,
My doubt is:
Can a variable (instance variable ANGLE in the program) be made static and private simultaneously ?
Static keywords provides a global access to the variable ,and private restricts it in the class.
So ,how can both be used together .
Thanks and best regards,
Srijith
About Question enthuware.ocajp.i.v7.2.904 :
Moderator: admin
-
- Posts: 2
- Joined: Tue Aug 18, 2015 8:05 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.904 :
Yes, you can make any field static as well as private. Whether you should make a field static or not depends on how you are modeling your classes. In this case, it is quite clear that angle should be an instance fields because every triangle instance will have an angle. If you make it static, it means a triangle instance does not have an angle. Instead, all the triangle instances will share one angle. If that is what you want, you can certainly do it. There is no restriction. However, angle will not be considered a "property" of a Triangle object in that case.
Who is online
Users browsing this forum: No registered users and 5 guests