About Question enthuware.ocajp.i.v7.2.904 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Srijith
Posts: 2
Joined: Tue Aug 18, 2015 8:05 am
Contact:

About Question enthuware.ocajp.i.v7.2.904 :

Post by Srijith »

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

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.904 :

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests