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 static uint numberOfPlanetsCreated; private double mass; ... public static double CalculateGravity(...) { ... } public double Density(...) { ... } } Is it possible to
|
7: | Among other methods, your class Planet contains two methods of approximately the same length. One is a static method related to the Planet class, the other is an instance method related to a particular Planet object. Suppose 100 objects of type Planet exist inside your running solar system simulation. Is the following statement true or false? "All the instance methods of the Planet class take up approximately 100 times more memory than the static method." Why? |
8: | Consider the following method definition: public void MyMethod(ref int myValue, int yourValue) { myValue = 100; yourValue = 200; } Which of the following calls to MyMethod are correct and, if correct, what is the value of myArgument and yourArgument after MyMethod returns (myArgument and yourArgument are both of type int and initially both contain the value 0)?
|
9: | Is the following method correct? Why or why not? public int Sum(out int x, int y) { return x + y; } |
10: | Consider the following method header: public double Average(params int[] numbers) Which of the following calls to this method are valid? (myArray is an array of base type int with 100 elements.)
|
11: | The following two method headers were found inside the same class. What can you call the methods? public int Sum(int number1, int number2) public double Sum(double number1, double number2) |
12: |
|
13: | A class contains the following method header: public uint Sum(uint x, uint y) Is the following method call valid? Why or why not? (myByte and yourByte are both of type byte, which is different from Sum's parameter types uint.) Sum(myByte, yourByte) |
14: | Consider the following class called Planet: class Planet { private double myMass = 2000000; public double DoSomething(double myMass) { return (myMass * this.myMass) + myMass; } } What value will the following method call have when DoSomething returns (if the value of the instance variable myMass is still 2000000)? DoSomething(20.0) |