Chapter 4

4.2.1

            //Create an account object and assign it to MyAccount
            Account myAccount = new Account();

before you call a method of that class you need to actually create that class.

Use an object-creating expression
new Account()

The 
The new keyword creates a new object of the specified class which is Account.

4.2.2 Calling Class Account's GetName Method

The method GetName in the Account class job is to 
Return the account name that stored in a particular Account object

//Display myAccount's initial name(there isn't one yet)
            Console.WriteLine($"Initial name is: {myAccount.GetName()}");

in order to display the myAccount name by calling the object "GetName" method you need

  • The object name (MyAccount) 
  • The member access operator (.)
  • The method name
  • Set of parentheses().
The empty set of parentheses indicate that "GetName" does not require any additional information
to perform a task.

When "Main" calls the "GetName"



4.2.3 Inputting a Name from the User

Prompt and input the name 
 string theName = Console.ReadLine();

We use "Console.ReadLine" which is a console method to read the username and assign it to the string variable name "TheName".

4.2.4 Calling Class Account’s SetName Method

"SetName" is an "Account" method, that when you call it the method store the account name in a particular "Account" object.


4.3.2 Keyword class and the Class Body


4.3.3 Instance Variable name of Type string

Objects of the class carry instance variable with them throughout their lifetimes.
Each object has its own copy of the class's instance variables.
normally a class also contain methods and properties.
these manipulate the instance variables.

instance variable declared inside of the class but outside of the class's methods and properties.

4.3.4 SetName Method

The first line of code of each method is the method header.








Void:

 means that the methods do not return any information when it completes its task.


Parameter:

A method can require one or two parameter's that represent the data its needs to perform its task.
SetName parameter is the accountName.
Method SetName declares a string parameter accountName - which receives the name that's
to SetName as an argument.

Parameter List:

Each parameter must specify a type followed by a parameter name(accountName).
when there more than one parameter, they are placed in a comma-separated list.

Method Body:

Every method body is delimited with a  left brace and closing right brace.
Within the braces are one or more statements that perform the method's task(s).
SetName Method's contained one statement.

4.3.5 GetName Method 








GetName has an empty parameter list which means its not required any additional information to perform its task.



return:

When a method with a return type other than void, It must return a result to his caller.



















Comments