20 terms

Classes in C#

STUDY
PLAY

Terms in this set (...)

class
In the C# language (and in most languages), an object is referred to as a _____.
Static methods have no way of knowing which instance of an object's non-static data you might want to
access
Why can't you access non-static class data from a static class method?
A reference data type
A class property must have the following data type:
private
Which keyword should replace the "???" question marks below to ensure the currentPlayer
member can only be accessed by TicTacToe objects?

class TicTacToe{??? int currentPlayer;}
You cannot declare a function outside of a class
What is wrong with the following code?

public void StartGame()
{
}
class TicTacToe
{
}
new Game.TicTacToe();
Given the code below, which of the following statements will create a new TicTacToe object?

namespace Game
{
class TicTacToe
{
}
}
Protected members can be accessed only by sub-classes
When is it possible for a class to access a "protected" data member of another class?
Prevent external objects from accidentally changing internal data & Hide internal implementation so it can be freely changed
Why is it a good idea to declare internal methods and data as "private"?
public TicTacToe(int currentPlayer)
How would you declare a constructor for the "TicTacToe" class that requires an integer
parameter?
When the object is created with the "new" keyword
When is a class constructor method called?
private static string PLAYER1_SYMBOL = "X";
Which statement below will replace the "???" question marks to declare a private, static
string variable on the TicTacToe class named "PLAYER1_SYMBOL" and initialize it to the
value "X"?

class TicTacToe{ ????}
false
T/F
If you assign one class variable to another, you have created a copy of that class variable.
true
T/F
You can assign default values to class properties when you declare them.
You can define any sort of method you like with different return types and input and output parameters
What type of methods can you create inside a class?
public
What type of access is NOT recommended for class properties?
The program will cause an error when the numWheels property is accessed.
Consider the following code:
class Car
{
public String make;
private int numWheels = 4;
}
What happens when you run the following code:

Car myCar = new Car();
myCar.make="Tucker";
myCar.numWheels=2;
true
T/F
A static property is especially useful for any property that is intended to be a global setting.
To properly initialize any necessary information in the class
What is the purpose of constructor parameters?
Properties and methods that belong to all instances of the class simultaneously
What are static methods and properties?
true
T/F
Class constructors must have the same name as the class itself.