حذيفة محمد طاهر نصر
What is the purpose of operator new? Explain what happens when 4.5
.this keyword is used in an application
ANS: The purpose of operator new is to create an object of a class. When operator new is
used in an application, first a new object of the class to the right of new is created, then the
.class’s constructor is called to ensure that the object is initialized properly
What is a default constructor? How are an object’s instance 4.6
?variables initialized if a class has only a default constructor
ANS: A default constructor is a constructor provided by the compiler when you do not
specify any constructors in the class. When a class has only the default constructor, its
instance variables are initialized to their default values. Variables that contain numbers are
initialized to 0, variables of type bool are initialized to false, and reference-type variables are
.initialized to null
.Explain the purpose of an instance variable 4.7
ANS: A class provides an instance variable (or several instance variables) when each object
of the class must maintain information separately from all other objects of the class. For
example, a class called Account that represents a bank account provides an instance variable
to represent the balance of the account. Each Account object maintains its own balance and
.does not know the balances of the bank’s other accounts
Explain how an application could use class Console without using a 4.8
.using directive
ANS: If every use of a class’s name in an application is fully qualified, there is no need for a
using directive. A class’s fully qualified name consists of the class’s namespace followed by a
dot and the class name. For example, an application could use class Console if every use of
.Console in the application were specified as System.Console
Explain why a class might provide a property for an instance 4.9
.variable
ANS: An instance variable is typically declared private in a class so that only the methods
(and properties) of the class in which the instance variable is declared can manipulate the
variable. In some cases, it may be necessary for an application to modify the private data. A
class’s designer can provide a public property that enables an application to specify the
value for, or retrieve the value of, a private instance variable. The property’s set accessor
can ensure that the instance variable is set only to valid values. Using properties to access
private fields allows the modification of the internal representation of the object without
.affecting the clients of the class