Questions are in doc files. All answer should be correct
multiplechoicequestion.docx

module_nine_powerpoint_c_.pptm

module_ten_powerpoint_c_.pptm

Unformatted Attachment Preview

Introduction to programming using C#
Question 1
An object is a ___ of a class.
Property
object
method
instantiation
QUESTION 2
Fields within a class should be public.
True
False
QUESTION 3
Properties or instance methods, within a class, should be public.
True
False
QUESTION 4
How many arguments can be used in a Constructor header?
1
10
Any amount.
0
QUESTION 5
The default constructor
both
none of these
sets numeric fields to 0
has empty parameters
10 points Saved
QUESTION 6
Assume that you have created a class named Student with a constructor defined as Student(int
age). Which of the following overloaded constructors could coexist with the Chair constructor
without ambiguity?
none of these
Student(int age, string name)
Student(int age)
both
QUESTION 7
A collection of methods that can be used by any class, as long as the class provides a definition
to override the collection’s definitions is
a class
a superclass
an interface
a template
QUESTION 8
When you create a class and want to include the capability to compare its objects so they can use
the Array.Sort() or Array.BinarySearch() method, you must
Use the CompareTo() Method
Create a destructor
Create a constructor
Use the IComparable () method
QUESTION 9
You can use the instance variable field as the identifier for an instance method.
Example:
private int age;
public int age { get; set; }
True
False
QUESTION 10
Arrays can hold references to objects.
True
False
Module Nine
Class Concepts
Concepts / Vocabulary
• Classes can be considered application • Instance Variables (known as fields)
programs that contain a Main ()
hold object attributes or data
method.
components for a class.
• Classes can hold objects that can be
• Instance Methods:
instantiated by another class.
• Associated with objects and every
Everything is essentially an object or a
instance of the class will have the same
member of another class because
methods.
objects are one property or one
element of a class.
Concepts / Vocabulary
• Class Header:
• Creating a Class:
• Like methods, it has an optional access
class ClassName
modifier. A method default access
modifier is private but a class default is
{
internal.
• We us the keyword class to create a
class, followed by an identifier or name
for the class.
• Also like a method, we can use other
access modifiers such as public,
protected, internal and private.
// Instance variables and
// methods can go inside
//the braces.
}
Concepts / Vocabulary
Module Nine
Instance Variables and Methods
Concepts / Vocabulary
When a class is created, we also define
the attributes and properties of the
class. This would include the variables
or fields of a class, properties or
objects of the class and methods.
When we use private fields within a class,
it is considered information hiding.
The fields of a class have their own set
of access modifiers that include: new,
public, protected, internal, private,
static, readonly, and write.
This allows you to control outside access
to data by controlling private data from a
public method.
*Most fields will be private because they
offer the highest level of security.
Although not always the case, it would be
good to make the class methods public.
Concepts / Vocabulary
We are able to use the variable idNumber even though it is private because we made the
method public. So we can pull a private source from a public source and is why we make
methods public. You can use the variable with better security this way.
Concepts / Vocabulary
• Has-a Relationship:
• Defines the instance in which a class has
objects of another class.
• Composition:
• Using an object within an object.
• If this was a bank program, you would
have a bank account class buy you
would also have a class for actual
customers that use objects from the
bank account class.
Module Nine
Creating Objects
Concepts / Vocabulary
• Creating an Object:
• When you create or declare a class, it
does not contain or come pre-loaded
with objects. All objects must be
created.
• To create an object we must:
• 1) Declare an object type and a name
(identifier).
• 2) Create the object.
• Reference Type:
• The identifier we use for the object is
how we reference its location or
memory address.
• When we create an object we can call
its constructor.
Concepts / Vocabulary
• Class Object Example:
Employee bob = new Employee ();
Bob.WelcomeMsg();
• Passing Objects to Methods:
• You can pass objects to methods just
like other data types:
• Example:
(in main)
Module Nine
Properties
Concepts / Vocabulary
• Property:
• The member of a class that provides access
to a field. A Get and Set will be defined for
setting and retrieving field information.
• The setter and getter are known as
accessors. The “set” sets the value for a field
and the “get” returns the stored value of a
field.
• Properties are linked to an object using the
“.”.
• Ex. student.Age;
• Field Example:
• private int age;
• Property Example:
Concepts / Vocabulary
• Auto-Implemented Property:
• The implementation or the set/get are
automatically created for you. You do
not need to declare the field that
corresponds with the property.
Class Student
{
public int Age (get; set;)
public string Name (get; set;)
}
Module Nine
This reference and public/private data
Concepts / Vocabulary
• Why care about the Accessibility?
• When Programming, data should be
hidden whenever possible, you never
really want information to be public if
you can help it. Instead, information
should be accessed by accessors.
• Public data fields can be used when all
the objects of a class contain the same
value.
• You can create a constant variable with
a class and it will always be static or it
will always belong to the entire class,
rather than a particular instance.
Concepts / Vocabulary
• Understanding the “this” Reference
• The This reference is an implicitly
passed reference.
• It tells the method which instance or
“scenario” of the class we are going to
use.
• You can also pass a parameter to a
this.reference.
Module Ten
Using Contructors
Concepts / Vocabulary
• Constructors:
• A special method that instantiates an
object. There is a default constructor
that automatically supplies a
constructor with no parameters.
• The default values of an object are
initialized with a default constructor.
• Book book1 = new Book();
• A default constructor takes no
arguments; however, you are able to
set information directly into them.
• public Book()
{
ReaderName = “Nicole”;
}
Concepts / Vocabulary
• Passing Parameters:
• You can create constructors that
receive different arguments. In fact, you
can create several constructors to
handle different circumstances.
public Book ()
{
ReaderName = Nicole;
}
——————————————public Book (string name)
{
ReaderName = name;
}
Concepts / Vocabulary
• Overloading Constructors:
• C# provides a default constructor even
if you do not provide your own.
• That being said, you can overload any
constructor and you can write as many
constructors as you want—however,
beware redundancy.
Module Ten
Object Initializers
Concepts / Vocabulary
• Initializers:
• Gives the programmer the ability to assign vales to
object properties (which in return their fields)
without calling the constructor, or passing a
parameter.
• *Requires a default constructor within the class.
• Example:
Student aStudent = new Student (StudentAge = 25);
Concepts / Vocabulary
• Benefits:
• Allows you to create multiple objects with
different initial assignments.
• This means you do not need to worry about
overloading multiple constructors.
• Example:
• Class Student
{
public int Age { get; set; }
• It also allows you to create objects with different
starting values.
public string Name { get; set; }
public int Id { get; set; }
public Student()
{
Age = 25;
Name = Nicole;
Id = 2130498;
}
}
Module Ten
Overloading Operators
Concepts / Vocabulary
• Overloading Operators:
• Allows you to use arithmetic symbols
with an object.
• Unary Operators:
• +, -, !, ++, –, true, false
• Binary Operators:
• +, -, *, /, %, &, |, ==, !=, >, <, >=, <= • You cannot overload the following: • =, &&, ||, new • Example: Module Ten Using Arrays with Objects Concepts / Vocabulary • Declaring Arrays: • Like any other type of information, arrays can also hold objects. • When you crate the array from a reference type (such as a class), the array holds the memory locations of the objects. • Arrays refer to the objects instead of containing objects. • Example: Concepts / Vocabulary • Methods with Arrays of Objects: • CompareTo(): • Used by the Sort() and BinarySearch(). • Sorting objects requires the use of an interface. • We have to tell the compiler which field to use in the comparison. • Interface: • A collection of methods that can be used by any class. • It must have a definition to override the interface method definitions in oerder to be used with any class. • When a methos id overrideen, it takes precedence over the original version. Concepts / Vocabulary • IComparable: • Default interface for the System namespace. • Contains the definition for the CompareTo() method. • Compares one object to another object and returns an integer. Interface Icomparable { int CompareTo(Object e); } • Negative Return: • The instance is less than the compared object. • Zero Return: • The instance is equal to the compared object. • Positive Return: • The instance is greater than the compared object. Concepts / Vocabulary Module Ten Destructors Concepts / Vocabulary • Destructors: • Used to destroy an instance of a class. The opposite of a constructor. • They can be usd to destroy an instance when that instances goes out of scope. • We have to explicitly declare a destructor using the tilde (~) followed by the class name. ... Purchase answer to see full attachment