1 / 8

Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539 xiang.lian@utrgv

CSCI 3328 Object Oriented Programming in C# Chapter 9 : Classes and Objects: A Deeper Look – Exercises. Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539 xiang.lian@utrgv.edu. Objectives. In this chapter, you will do some exercises about: classes and objects

robertobest
Download Presentation

Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539 xiang.lian@utrgv

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539 xiang.lian@utrgv.edu

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

  3. 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. ToString B. Format C. WriteLine 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. ToString D. [ ]

  4. 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

  5. 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.

  6. 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.

  7. 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.

More Related