COSC 1315

Programming Fundamentals

 Practice Text #110

Basic Object-Based Program Structure

Revised: February 3, 2007
By Richard G. Baldwin

File Pfsg00110.htm
Practice Text Index


Welcome

The practice tests in this series were written specifically for the benefit of my students in COSC 1315, Fundamentals of Programming.  They consists of questions, answers, and explanations.  The questions are based on the material covered in my series of online lecture notes for the course.  Each practice test is keyed to a specific lecture.  This practice test is keyed to lecture #110 titled Basic Object-Based Program Structure.

Questions



110-1.  True or False.  The sample programs in lesson #110 titled Basic Object-Based Program Structure are Object-Oriented programs.

Answer and Explanation

110-2.  True or False.  An Object-Oriented program exhibits three critical attributes:

Answer and Explanation

110-3.  True or False.  It is easy to eliminate all global functions in C++.

Answer and Explanation

110-4.  True or False.  As is the case in C++, the C# programming language also requires a global Main function (which is usually called a method instead of a function).

Answer and Explanation

110-5.  True or False.  A static function or method can be accessed without a requirement to instantiate an object of the class.

Answer and Explanation

110-6.  The program shown in Listing 110-6 is:

Listing 110-6.
public class Hello1{
  public static void Main(){
    System.Console.WriteLine("Hello World");
  }//end Main
}//end class Hello01

Answer and Explanation

110-7.  What output is produced by the C#  program shown in Listing 110-7?

Listing 110-7.
public class Hello1{
  public static void Main(){
    System.Console.WriteLine("Hello World");
  }//end Main
}//end class Hello01

Answer and Explanation

110-8.  True or False.  To compile C# programs, you must use a fancy IDE such as Microsoft Visual Studio.

Answer and Explanation

110-9.  The program shown in Listing 110-9 is:

Listing 110-9.
class Hello1{
  public static void main(String[] args){
    System.out.println("Hello World");
  }//end main
}//End Hello1 class

Answer and Explanation

110-10.  What output is produced by the Java program shown in Listing 110-10?

Listing 110-10.
class Hello1{
  public static void main(String[] args){
    System.out.println("Hello World");
  }//end main
}//End Hello1 class

Answer and Explanation

110-11.  The program shown in Listing 110-11 is:

Listing 110-11.
#include <iostream>
using namespace std;

class Hello1{ 
  public:
  static void classMain(){
    cout << "Hello World" << endl;
  }//End classMain function
};//End Hello1 class
//---------------------------------------------//

int main(){
  Hello1::classMain();
  return 0;
}//end main

Answer and Explanation

110-12.  What output is produced by the C++ program shown in Listing 110-12?

Listing 110-12.
#include <iostream>
using namespace std;

class Hello1{ 
  public:
  static void classMain(){
    cout << "Hello World" << endl;
  }//End classMain function
};//End Hello1 class
//---------------------------------------------//

int main(){
  Hello1::classMain();
  return 0;
}//end main

Answer and Explanation

110-13.  True or False. There are essentially four kinds of functions in C++:

Answer and Explanation

110-14.  True or False.  Global functions are essentially accessible by any code in any function that knows the name of the global function.

Answer and Explanation

110-15.  True or False.  Class functions are functions that are defined inside a class without using the static keyword.

Answer and Explanation

110-16.  True or False.  Class functions in C++ can be declared public, private, package-private, or protected.

Answer and Explanation

110-17.  True or False.  Public class functions can be accessed by any code in any function that knows the name of the function and the name of the class in which the function is defined.

Answer and Explanation

110-18.  True or False.  Public static functions can be accessed in the total absence of an object of the class.

Answer and Explanation

110-19.  True or False.  Instance functions are functions that are defined inside a class without using the static keyword.

Answer and Explanation

110-20.  True or False.  For efficiency purposes, only one copy of an instance function actually exists.  However some "smoke and mirrors" is used to make it appear that every object instantiated from the class has its own copy of every instance function that is defined in the class.

Answer and Explanation

110-21.  True or False. 

Answer and Explanation

110-22.  True or False.  Instance functions can be declared public, private, or protected.  Public instance functions can be invoked by any code that has access to the object to which the functions belong.

Answer and Explanation

110-23.  True or False.  It is common practice in object-oriented programming to cause an object to encapsulate:

Answer and Explanation

110-24.  True or False.  The program in Listing 110-24:

Listing 110-24.
#include <iostream>
using namespace std;

class Hello2{ 
  public:
  static void classMain(){
    Hello2* ptrToObject = new Hello2();
    ptrToObject -> doSomething();

  }//End classMain function
  //-------------------------------------------//

  //An instance function belonging to the Hello2
  // object.
  void doSomething(){
    cout << "Hello World\n";
  }//end doSomething function
};//End Hello2 class
//---------------------------------------------//

int main(){
  Hello2::classMain();
  return 0;
}//end main

Answer and Explanation

110-25.  True or False.  The boldface statement in Listing 110-25:

Listing 110-25.
#include <iostream>
using namespace std;

class Hello2{ 
  public:
  static void classMain(){
    Hello2* ptrToObject = new Hello2();
    ptrToObject -> doSomething();

  }//End classMain function
  //-------------------------------------------//

  //An instance function belonging to the Hello2
  // object.
  void doSomething(){
    cout << "Hello World\n";
  }//end doSomething function
};//End Hello2 class
//---------------------------------------------//

int main(){
  Hello2::classMain();
  return 0;
}//end main

Answer and Explanation

110-26.  True of False.  The boldface statement in Listing 110-26 effectively:

Listing 110-26.
#include <iostream>
using namespace std;

class Hello2{ 
  public:
  static void classMain(){
    Hello2* ptrToObject = new Hello2();
    ptrToObject -> doSomething();

  }//End classMain function
  //-------------------------------------------//

  //An instance function belonging to the Hello2
  // object.
  void doSomething(){
    cout << "Hello World\n";
  }//end doSomething function
};//End Hello2 class
//---------------------------------------------//

int main(){
  Hello2::classMain();
  return 0;
}//end main

Answer and Explanation



Copyright 2007, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

About the author

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web.

Richard has participated in numerous consulting projects involving Java, XML, or a combination of the two.  He frequently provides onsite Java and/or XML training at the high-tech companies located in and around Austin, Texas.  He is the author of Baldwin's Java Programming Tutorials, which has gained a worldwide following among experienced and aspiring Java programmers. He has also published articles on Java Programming in Java Pro magazine.

Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.

Baldwin@DickBaldwin.com


Answers and Explanations

Answer 26

True

Back to Question 26

Explanation 26

Answer 25

False

Back to Question 25

Explanation 25

Answer 24

True

Back to Question 24

Explanation 24

Answer 23

True

Back to Question 23

Explanation 23

Answer 22

True

Back to Question 22

Explanation 22

Answer 21

True

Back to Question 21

Explanation 21

Answer 20

True

Back to Question 20

Explanation 20

Answer 19

True

Back to Question 19

Explanation 19

Answer 18

True

Back to Question 18

Explanation 18

Answer 17

True

Back to Question 17

Explanation 17

Answer 16

False

Back to Question 16

Explanation 16

Answer 15

False

Back to Question 15

Explanation 15

Answer 14

True

Back to Question 14

Explanation 14

Answer 13

False

Back to Question 13

Explanation 13

Answer 12

C.  Hello World

Back to Question 12

Explanation 12

Answer 11

A.  A C++ program.

Back to Question 11

Explanation 11

Answer 10

C.  Hello World

Back to Question 10

Explanation 10

Answer 9

B.  A Java program.

Back to Question 9

Explanation 9

Answer 8

False

Back to Question 8

Explanation 8

Answer 7

C.  Hello World

Back to Question 7

Explanation 7

Answer 6

C.  A C# program.

Back to Question 6

Explanation 6

Answer 5

True

Back to Question 5

Explanation 5

Answer 4

False

Back to Question 4

Explanation 4

Answer 3

False

Back to Question 3

Explanation 3

Answer 2

True

Back to Question 2

Explanation 2

Answer 1

False

Back to Question 1

Explanation 1



Copyright 2007, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

About the author

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web.

Richard has participated in numerous consulting projects involving Java, XML, or a combination of the two.  He frequently provides onsite Java and/or XML training at the high-tech companies located in and around Austin, Texas.  He is the author of Baldwin's Java Programming Tutorials, which has gained a worldwide following among experienced and aspiring Java programmers. He has also published articles on Java Programming in Java Pro magazine.

Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.

Baldwin@DickBaldwin.com

-end-