Deck 4: Introduction to Classes,Objects,Methods and Strings
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/50
العب
ملء الشاشة (f)
Deck 4: Introduction to Classes,Objects,Methods and Strings
1
Which of the following statements is false
A) Variables declared in a particular method's body (such as Main) are local variables, which can be used only in that method.
B) Each method can access its own local variables and those of other methods.
C) When a method terminates, the values of its local variables are lost.
D) A method's parameters also are local variables of the method.
A) Variables declared in a particular method's body (such as Main) are local variables, which can be used only in that method.
B) Each method can access its own local variables and those of other methods.
C) When a method terminates, the values of its local variables are lost.
D) A method's parameters also are local variables of the method.
B
Each method can access its own local variables and those of other methods.Actually,each method can access its own local variables,but not those of other methods.
Each method can access its own local variables and those of other methods.Actually,each method can access its own local variables,but not those of other methods.
2
By default,everything in a class is ________,unless you specify otherwise by providing access modifiers.
a) public
b) private
c) protected
d) None of the above.
a) public
b) private
c) protected
d) None of the above.
False
Actually,the default initial value for string instance variables is null
Actually,the default initial value for string instance variables is null
3
The code
myAccount.SetName(theName);
calls myAccounts's SetName method,passing theName's value as SetName's argument.
myAccount.SetName(theName);
calls myAccounts's SetName method,passing theName's value as SetName's argument.
True
4
Each class you create becomes a new type you can use to create objects,so C# is a(n)________ programming language.
A) type sensitive
B) flexible
C) elastic
D) extensible
A) type sensitive
B) flexible
C) elastic
D) extensible
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
5
Which of the following statements about creating,compiling and running a Visual C# project with two classes is false
A) The IDE automatically recognizes as the app's entry point the class that contains Main.
B) When you select Build > Build Solution in Visual Studio, the IDE compiles all the files in the project to create the executable app.
C) If you do not build the app before running it, typing Ctrl + F5 will build the app first and run the app only if there are no compilation errors.
D) In a given project, declaring a Main method in more than exactly one class results in a runtime error.
A) The IDE automatically recognizes as the app's entry point the class that contains Main.
B) When you select Build > Build Solution in Visual Studio, the IDE compiles all the files in the project to create the executable app.
C) If you do not build the app before running it, typing Ctrl + F5 will build the app first and run the app only if there are no compilation errors.
D) In a given project, declaring a Main method in more than exactly one class results in a runtime error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
6
Which of the following statements is false
A) Normally, a class also contains methods and properties. These manipulate the instance variables belonging to particular objects of the class.
B) Instance variables are declared inside the bodies of the class's methods and properties.
C) Clients of a class cannot access the class's private instance variables.
D) Clients of a class can access the class's public methods.
A) Normally, a class also contains methods and properties. These manipulate the instance variables belonging to particular objects of the class.
B) Instance variables are declared inside the bodies of the class's methods and properties.
C) Clients of a class cannot access the class's private instance variables.
D) Clients of a class can access the class's public methods.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
7
A method such as Main "drives" an object by calling its methods-without having to know how the class's internal mechanisms work.In this sense,the class containing method Main is referred to as a driver class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
8
Consider the code (in class Account):
Public string GetName()
{
Return name;
}
Which of the following statements is false
A) The method returns a particular Account object's name to the caller-a string, as specified by the method's return type.
B) The method has an empty parameter list, so it does not require additional information to perform its task.
C) When a method with a return type other than void is called and completes its task, it must return a result to its caller.
D) All of the above are true.
Public string GetName()
{
Return name;
}
Which of the following statements is false
A) The method returns a particular Account object's name to the caller-a string, as specified by the method's return type.
B) The method has an empty parameter list, so it does not require additional information to perform its task.
C) When a method with a return type other than void is called and completes its task, it must return a result to its caller.
D) All of the above are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
9
Consider the code:
Console.WriteLine($"Initial name is: {myAccount.GetName()}");
Which method is called first
A) WriteLine
B) GetName
C) They execute at the same time.
D) None of the above.
Console.WriteLine($"Initial name is: {myAccount.GetName()}");
Which method is called first
A) WriteLine
B) GetName
C) They execute at the same time.
D) None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
10
Consider the code:
Public void SetName(string accountName)
{
Name = accountName;// store the account name
}
Which of the following statements is false
A) The first line of each method declaration is the method header.
B) The method's return type (which appears to the left of the method's name) specifies the type of data the method returns to its caller after performing its task.
C) The return type void indicates that when SetName completes its task, it does not return any information to its calling method.
D) A method requires one or more parameters that represent the data it needs to perform its task.
Public void SetName(string accountName)
{
Name = accountName;// store the account name
}
Which of the following statements is false
A) The first line of each method declaration is the method header.
B) The method's return type (which appears to the left of the method's name) specifies the type of data the method returns to its caller after performing its task.
C) The return type void indicates that when SetName completes its task, it does not return any information to its calling method.
D) A method requires one or more parameters that represent the data it needs to perform its task.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
11
Most instance variables are declared ________.
A) public
B) protected
C) private
D) None of the above.
A) public
B) protected
C) private
D) None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
12
The fact that we could create and manipulate an Account object without knowing its implementation details is called ________.This is one of the most powerful software-engineering benefits of object-oriented programming.
A) inheritance
B) shadowing
C) overriding
D) abstraction
A) inheritance
B) shadowing
C) overriding
D) abstraction
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
13
An attempt by a method that's not a member of a particular class to access a private member of that class is a runtime error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
14
Method ReadLine reads a whole line,including all the characters the user types up to and including the newline that the user typed by pressing Enter.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
15
Instance variables are required to be explicitly initialized before they're used in a program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
16
Which of the following statements is false
A) Each object of a class shares one copy of the class's instance variables.
B) Each class declaration is typically stored in a file having the same name as the class and ending with the .cs filename extension
C) Class, property and method names begin with an initial uppercase letter (i.e., Pascal case); variable names begin with an initial lowercase letter (i.e., camel case).
D) A class has attributes, implemented as instance variables. Objects of the class carry these instance variables with them throughout their lifetimes.
A) Each object of a class shares one copy of the class's instance variables.
B) Each class declaration is typically stored in a file having the same name as the class and ending with the .cs filename extension
C) Class, property and method names begin with an initial uppercase letter (i.e., Pascal case); variable names begin with an initial lowercase letter (i.e., camel case).
D) A class has attributes, implemented as instance variables. Objects of the class carry these instance variables with them throughout their lifetimes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
17
Consider the code:
MyAccount.SetName(theName);
Which of the following statements is false
A) When this method executes, the argument value in the call's parentheses (i.e., the value stored in theName) is copied into the corresponding parameter in the method's header.
B) Each parameter must specify a type followed by a parameter name. When there are multiple parameters, they are placed in a comma-separated list.
C) The number and order of arguments in a method call must match the number and order of parameters in the method declaration's parameter list.
D) All of the above are true.
MyAccount.SetName(theName);
Which of the following statements is false
A) When this method executes, the argument value in the call's parentheses (i.e., the value stored in theName) is copied into the corresponding parameter in the method's header.
B) Each parameter must specify a type followed by a parameter name. When there are multiple parameters, they are placed in a comma-separated list.
C) The number and order of arguments in a method call must match the number and order of parameters in the method declaration's parameter list.
D) All of the above are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
18
Which of the following statements is false
A) Set and Get methods can validate attempts to modify private data and control how that data is presented to the caller, respectively.
B) If an instance variable were public, any client of the class could see the data and modify it, including setting it to an invalid value.
C) public data allows client-code programmers to write code that depends on the class's data format. If the class's owner changes that format, any client code dependent on it would "break" and would need to be adjusted to the new format, making it subject to break again.
D) All of the above are true.
A) Set and Get methods can validate attempts to modify private data and control how that data is presented to the caller, respectively.
B) If an instance variable were public, any client of the class could see the data and modify it, including setting it to an invalid value.
C) public data allows client-code programmers to write code that depends on the class's data format. If the class's owner changes that format, any client code dependent on it would "break" and would need to be adjusted to the new format, making it subject to break again.
D) All of the above are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
19
By default,instance variables are not initialized.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
20
Making a class's instance variables public and its methods private and accessing those instance variables only through the class's methods and properties facilitates debugging,because problems with data manipulations are localized to the methods (and properties).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which of the following properly declares an auto-implemented Name property of type string
A) public string Name { get, set }
B) public string Name { get, set, }
C) public string Name { get; set; }
D) public string Name { get: set: }
A) public string Name { get, set }
B) public string Name { get, set, }
C) public string Name { get; set; }
D) public string Name { get: set: }
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
22
You should think of a C# class's attributes as instance variables.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
23
Keywords set and value can be used only in set accessors.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
24
C# is case sensitive,so Name and name are distinct identifiers.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
25
Which of the following statements is false
A) If you later decide to include other logic in the get or set accessors, you can simply implement the property and an instance variable.
A) It's common to see property definitions where the get accessor simply returns private instance variable name's value and the set accessor simply assigns a value to the instance variable-no other logic appears in the accessors. For such simple cases, C# provides auto-implemented properties.
B) With an auto-implemented property, the C# compiler automatically creates a public instance variable, and the get and set accessors for getting and setting that instance variable.
C) With an auto-implemented property you can implement the property trivially, which is handy when you're first designing a class.
A) If you later decide to include other logic in the get or set accessors, you can simply implement the property and an instance variable.
A) It's common to see property definitions where the get accessor simply returns private instance variable name's value and the set accessor simply assigns a value to the instance variable-no other logic appears in the accessors. For such simple cases, C# provides auto-implemented properties.
B) With an auto-implemented property, the C# compiler automatically creates a public instance variable, and the get and set accessors for getting and setting that instance variable.
C) With an auto-implemented property you can implement the property trivially, which is handy when you're first designing a class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
26
Which of the following statements is false
A) Set methods can be programmed to validate their arguments and reject any attempts to set the data to bad values
B) A Get method always presents the data in the form in which it's stored.
C) Tightly controlling the access to and presentation of private data can greatly reduce errors, while increasing the robustness, security and usability of your programs.
D) All of the above are true.
A) Set methods can be programmed to validate their arguments and reject any attempts to set the data to bad values
B) A Get method always presents the data in the form in which it's stored.
C) Tightly controlling the access to and presentation of private data can greatly reduce errors, while increasing the robustness, security and usability of your programs.
D) All of the above are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
27
A method SetName might declare a parameter accountName to receive a new name to store in an Account object-a set accessor uses the implicitly declared keyword parameter for the same purpose.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
28
The following code:
Account account1 = new Account("Jane Green");
passes the string argument "Jane Green" to the Account object's Account method.
Account account1 = new Account("Jane Green");
passes the string argument "Jane Green" to the Account object's Account method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
29
Consider the code:
MyAccount.Name = theName;
Which assigns the string theName to myAccounts's Name property.Which of the following is false regarding when property Name is invoked by the expression myAccount.Name on the left of an assignment
A) The app transfers program execution to Name's set accessor.
B) Property Name's set accessor performs its task-that is, it stores in the myAccount object's name instance variable the string value that was assigned to property Name.
C) When Name's set accessor completes execution, program control returns to where the Name property was accessed, then execution continues at the next statement.
D) All of the above are true.
MyAccount.Name = theName;
Which assigns the string theName to myAccounts's Name property.Which of the following is false regarding when property Name is invoked by the expression myAccount.Name on the left of an assignment
A) The app transfers program execution to Name's set accessor.
B) Property Name's set accessor performs its task-that is, it stores in the myAccount object's name instance variable the string value that was assigned to property Name.
C) When Name's set accessor completes execution, program control returns to where the Name property was accessed, then execution continues at the next statement.
D) All of the above are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
30
Normally,constructors are declared private.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
31
Keyword get is a ________ keyword,because it's a keyword only in a property's body-elsewhere,get can be used as an identifier.
A) restricted
B) dependent
C) contextual
D) contingent
A) restricted
B) dependent
C) contextual
D) contingent
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
32
In the code:
Console.WriteLine($"Initial name is: {myAccount.Name}");
the expression myAccount.Name explicitly invokes the Name property's get accessor to get the value of myAccount's instance variable name.
Console.WriteLine($"Initial name is: {myAccount.Name}");
the expression myAccount.Name explicitly invokes the Name property's get accessor to get the value of myAccount's instance variable name.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
33
Which of the following statements is false
A) Each class you declare must provide a constructor with parameters that can be used to initialize an object when it's created.
B) C# requires a constructor call for every object that's created, so this is the ideal point to initialize an object's instance variables.
C) A constructor's identifier must be the class's name.
D) When you declare a class, you can provide your own constructor to specify custom initialization for objects of your class.
A) Each class you declare must provide a constructor with parameters that can be used to initialize an object when it's created.
B) C# requires a constructor call for every object that's created, so this is the ideal point to initialize an object's instance variables.
C) A constructor's identifier must be the class's name.
D) When you declare a class, you can provide your own constructor to specify custom initialization for objects of your class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
34
Which of the following statements is false
A) In any class that does not explicitly declare a constructor, the compiler provides a public default constructor (which always has no parameters).
B) When a class has only the default constructor, the class's instance variables are initialized to their default values: 0 for numeric simple types, false for simple type bool and null for all other types.
C) If you declare one or more constructors for a class, the compiler will not create a default constructor for that class.
D) If the compiler does not create a default constructor for an Account class, you will not be able to create an Account object with the expression new Account().
A) In any class that does not explicitly declare a constructor, the compiler provides a public default constructor (which always has no parameters).
B) When a class has only the default constructor, the class's instance variables are initialized to their default values: 0 for numeric simple types, false for simple type bool and null for all other types.
C) If you declare one or more constructors for a class, the compiler will not create a default constructor for that class.
D) If the compiler does not create a default constructor for an Account class, you will not be able to create an Account object with the expression new Account().
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
35
An important difference between constructors and methods is that constructors must specify a return type of void.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
36
Type ________ is designed to precisely represent numbers with decimal points,especially monetary amounts.
A) digit
B) decimal
C) float
D) double
A) digit
B) decimal
C) float
D) double
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
37
The property notation allows the client to directly manipulate the private instance variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
38
By convention,a property's identifier is the lowercase identifier of the instance variable that it manipulates-name is the property that represents instance variable Name.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
39
A property encapsulates a set accessor for storing a value into a variable and a get accessor for getting the value of a variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
40
If the following is a constructor
Public Account(string accountName)
{
Name = accountName;
}
Then what's the name of the class
A) Account
B) accountName
C) Name
D) None of the above.
Public Account(string accountName)
{
Name = accountName;
}
Then what's the name of the class
A) Account
B) accountName
C) Name
D) None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
41
It's always better to get the errors out of your programs at execution time,if possible,rather than at compilation time.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
42
Which of the following statements is false
A) A decimal instance variable is initialized to zero by default.
B) By default, a property's get and set accessors have the same access as the property.
C) A property's get and set accessors must have the same access modifiers.
D) We can declare a Balance property's set accessor private to indicate that it may be used only within its class, but not by the class's clients.
A) A decimal instance variable is initialized to zero by default.
B) By default, a property's get and set accessors have the same access as the property.
C) A property's get and set accessors must have the same access modifiers.
D) We can declare a Balance property's set accessor private to indicate that it may be used only within its class, but not by the class's clients.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
43
Local variables are initialized to their default values.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
44
Attempting to use an uninitialized local variable is a runtime error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
45
The Windows culture settings on the user's machine determine the format for displaying currency amounts,such as the commas vs.periods for separating thousands,millions,etc.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
46
When implementing a method of a class,the method should access the class's instance variables directly.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
47
Which of the following statements about the C format specifier is false.
A) It formats the string as currency.
B) It includes an appropriate currency symbol ($ in the U.S.) next to the number.
C) It separates digits with an appropriate separator character (in the U.S. its a comma between every digit.)
D) It sets the number of decimal places to two by default.
A) It formats the string as currency.
B) It includes an appropriate currency symbol ($ in the U.S.) next to the number.
C) It separates digits with an appropriate separator character (in the U.S. its a comma between every digit.)
D) It sets the number of decimal places to two by default.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
48
The benefits of data integrity are automatic when instance variables are made private.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
49
We could use a fully implemented Balance property to ensure that the set accessor's argument is valid before assigning it to the balance instance variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
50
We could use a fully implemented Balance property to ensure that the set accessor's argument is valid before assigning it to the balance instance variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck