Chapter 7 : Class Flashcards

1
Q

What is a class?

A
  1. The blueprint for an object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does a class specifies ? ( 2 )

A
  1. Fields
  2. Methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What can be created from the class?

A
  1. Object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the objected created from a class called?

A
  1. Instance of the class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to create a class?

A

class className
{
Member declaration(s)
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a constructor?

A
  1. Special method automatically executed when an object is created
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to create a object?

A

className objectName - new constructor

  • Coin myCoin = new Coin();
  • myCoin - Identifie that references an object of the Coin class
  • new - creates an instance of the Coin class
  • = - assigns the reference that was returend from the new operator to the myCoin identifie
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Where to create class? ( 2 )

A
  1. Save the class declaration in a separate .cs file
  2. Add it inside Form.cs file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a property?

A
  1. A class member that holds a piece of data about an object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a backing field?

A
  1. A variable that stores a value assigned to the property which the backing fields is associated with
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the access method of backing field?

A
  1. private
  • Protect it from accidental corruption
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does it do when a backing vield is public?

A
  1. Accessible directly by code outside the class without the need for accessors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the get accessor do?

A
  1. It is a method that returns the property’s value because it has a return statement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the set accessor do?

A
  1. It is a method gets the value stored in the backing field and assigns that value to the property
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When is get accessor executed?

A
  1. It is executed whenever the property is read
  • It has an implicit parameter named value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When is set accessor is executed?

A
  1. Whenever a value is assigned to the property
17
Q

What is a read-only property and how to set a read-only property?

A
  1. A read-only property can be read, but it cannot be meodified
  2. To ser a read-only property, simply do not write a set accessor for the property
18
Q

What is a parameterized constructor?

A
  1. A constructor that accepts arguments
19
Q

What is overloaded methods?

A
  1. Multiple versions of the same method
20
Q

How does the compiler know which method to call?

A
  1. Relies on the signarutre of a method which consists of the methods’s name, the data type, and argument kind of the method’s parameter
21
Q

When is a method is overloaded?

A
  1. Means that multiple methods in the same class have the same name but use different types of parameters
22
Q

Can constructors be overloaded?

A
  1. Yes
  • Compiler will find the matching constructor automatically
  • public BankAccount() { } // parameterless constructor
    public BankAccount(decimal startingBalance) { } // overloaded
    public BankAccount(double startingBalance) { } // overloaded
23
Q

How to I identify the classes? ( 3 )

A
  1. Get a written description of the problem domain
  2. Identify all the nouns ( pronouns and noun phrases ) in the description . Each of these is a potential class
  3. Refine the list to include only the class that are relavant to the problem
24
Q

What am I going to do once the class have been identified?

A
  1. Identify each class’s responsibilities
    • The things that the class is responsible for knowing -> variable, arrary, list
    • The actions that the class is responsible for doing
25
How to display a form?
ErrorForm myErrorForm = new ErrorForm(); myErrorForm.ShowDialog();
26
How to access labelText from different class?
GreetingsForm greetingsForm = new GreetingForm(); greetingsForm.messageLabel.Text = "Good day!" greetingsForm.ShowDialog();
27
What does a modal form do?
1. Must be closed or hidden before we can continue working with the rest of the application
28
What does a modeless form do?
1. Allows the user to switch focus to another form while it is displayed * Does not have to close a modeless form to switch focus to another form
29
What is the Flow of Executions for modal form?
1. Statement below ShowDialog method won't be execute until the modal form is closed statement; statement; messageForm.ShowDialog(); statement; statement; // not executed statement;
30
What is the Flow of Executions of modeless form?
1. Statement below ShowDialog method will execute immediately after the modeless from is displayed statement; statement; messageForm.Show(); statement; statement; // executed statement;