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

Chapter 12

Answers to Chapter 12 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?
A1: As a static variable, because the variable describes the Planet objects as a group.
2: Can you assign a value to a static variable even if no objects have been created?
A2: Yes.
3: Can a static variable be accessed from within an object of the class in which it is declared?
A3: Yes.
4: The following declaration was found inside a class:
public static const double MassOfElectron = 9.0e-28;

Is it correct? Why or why not?

A4: No. A const is ...

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