CSCI 3328 Object Oriented Programming in C Chapter

  • Slides: 8
Download presentation
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper

CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises UTPA – Fall 2012 1

Objectives • In this chapter, you will do some exercises about: – classes and

Objectives • In this chapter, you will do some exercises about: – classes and objects – Keywords such as this, static, readonly 2

Multiple Choices • A static method in the string class, called _______, is similar

Multiple Choices • A static method in the string class, called _______, is similar to method Console. Write, but returns a formatted string rather than displaying a string in a console window. – A. To. String B. Format C. Write. Line D. Static • If a method contains a local variable with the same name as one of its class's fields, the local variable ____ the field in that method's scope. – A. removes B. replaces the memory of C. hides D. is hidden by • The ______ is called by the garbage collector just before it reclaims an object's memory. – A. constructor B. method C. destructor D. variable • If a class declares constructors, the compiler will not create a(n) __. – A. method B. default constructor C. destructor D. variable • An object's _______method can be called implicitly when an object appears in code where a string is needed. – A. constructor B. destructor C. To. String D. [ ] 3

Multiple Choices (cont'd) • A(n) _____ variable represents classwide information that is shared by

Multiple Choices (cont'd) • A(n) _____ variable represents classwide information that is shared by all the objects of the class. – A. object B. private C. static D. public • Declaring an instance variable with keyword _____ specifies that the variable is not modifiable. – A. static B. private C. readonly D. ref • Properties can contain both ______accessors. – A. return and value B. get and value C. get and set D. set and return • Keyword _____introduces a class definition. – A. newclass B. classdef C. VC#class D. class 4

Multiple Choices (cont'd) • A class can yield many _____, just as a primitive

Multiple Choices (cont'd) • A class can yield many _____, just as a primitive data type can yield many values – A. names B. objects (instances) C. values D. types • Variables can be initialized ____. – A. when they are declared B. to their default values C. in a constructor D. All of the above • Instance variables declared private are not accessible_____. – A. outside the class B. by other methods of the same class C. inside the same class D. All of the above. 5

True/False Statements • You can use properties of an object in the select clause

True/False Statements • You can use properties of an object in the select clause of an LINQ query. • An object initializer first calls the class's constructor, then assigns the specified property values. • Base-class constructors are not inherited by derived classes. • Inheritance encourages the reuse of proven high-quality software. 6

True/False Statements (cont'd) • When a derived class redefines a base-class method, by using

True/False Statements (cont'd) • When a derived class redefines a base-class method, by using the same signature and return type, the derived class is said to overload that base-class method. • A base class's private members are accessible anywhere that the application has a reference to an object of that base class or to an object of any of its derived classes. • When an object of a derived class is instantiated, a base class constructor is called implicitly or explicitly. • Derived-class constructors can call base class constructors via the base keyword. 7

8

8