CSCI 3328 Object Oriented Programming in C Chapter
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects – Exercises Xiang Lian The University of Texas – Pan American Edinburg, TX 78539 lianx@utpa. edu 1
Objectives • In this chapter, you will – Do some exercises about classes and objects in C# 2
Multiple Choices • A class can have _____ object(s). – A. only 1 B. only 2 C. between 1 and 3 D. more than 1 • Every class declaration contains immediately by the class’s name – A. keyword B. public C. void keyword ____ followed D. class • Which of the following statements is true to create a new object of class My. Class in C#? – – A. My. Class obj = new My. Class () B. My. Class obj = new My. Class ; C. My. Class *obj = new My. Class (); D. My. Class obj = new My. Class (); • C# provides the following simple types for storing real numbers except for ____. – A. real B. float C. double D. decimal 3
Multiple Choices (cont'd) • Which of the following statements is the correct usage of Convert in C#? – – A. Console. Convert(); B. Convert. To. Decimal(); C. Convert. Read. Line(); D. Convert. To. Decimal(Console. Read. Line()); • Return type _______indicates that a method will not return any information when it completes its task. – A. NULL B. Nil C. Void D. void • Which of the following statements is correct? – – A. Console. Write. Line({0: C}, 3); B. Console. Write("Hello world!"); C. Console. Read. Line(x); D. Console. Read(x); 4
True or False Statements • 1. By convention, method names begin with a lowercase first letter and all subsequent words in the name begin with a capital first letter • 2. A property's get accessor enables a client to modify the value of the instance variable associated with the property • 3. Empty parentheses following a method name in a method declaration indicate that the method does not require any parameters to perform its task 5
True or False Statements (cont'd) • 4. After defining a property, you can use it the same way you use a method, but with empty parentheses, because no arguments are passed to a property • 5. Variable declared in the body of a particular method are known as instance variables and can be used in all methods of the class • 6. A property declaration must contain both a get accessor and a set accessor 6
7
- Slides: 7