O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Review Questions

1:You are writing a Planet class for a solar system simulation program. You need to keep track of the number of instantiated Planet objects. If you were to store this data as a variable inside Planet, should it be an instance variable or a static variable? Why?
2:Can you assign a value to a static variable even if no objects have been created?
3:Can a static variable be accessed from within an object of the class in which it is declared?
4:The following declaration was found inside a class:
public static const double MassOfElectron = 9.0e-28;

Is it correct? Why or why not?

5:Does it go against encapsulation principles to declare a const to be public?
6:A class called Planet contains the following declarations:
 class Planet { private ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required