CS 280 Final

Ace your homework & exams now with Quizwiz!

What is an overriding method?

An overriding method is one that is defined in the derived class to replace a virtual method inherited from an ancestor class. Calls to an overriding method must be dynamically bound. The purpose of an overriding method is to provide an operation in the subclass that is similar to one in the parent class, but is customized for objects of the subclass. Overriding methods in C++ must have exactly the same parameter profile as the overridden method. If there is any difference in the parameter profiles, the method in the subclass is considered a new method that is unrelated to the method with the same name in the ancestor class. The return type of the overriding method either must be the same as that of the overridden method or must be a publicly derived type of the return type of the overridden method. an overriding method is one that is defined in the derived class.

Why are destructors not as frequently needed in Java as they are in C++?

Because Java has an implicit garbage collection which stores all objects which was supposed to be destroyed.

In Java, all passed parameters of scalar types are passed

By-value

Which of the caller or callee saves the execution status information?

Caller

Who does the saving of the execution status (i.e., machine state), the caller or the called subprogram?

Caller subprogram.

From where are C++ class instances allocated?

Class instances can be static, stack dynamic, or heap dynamic.

What is the difference between a class variable and an instance variable?

Class variables are declared in the class definition using the static keyword prefix. all instances of a class share the same single copy of class variables. each instance of a class has its own copy of instance variables.

T/F A C++ class that has at least one virtual function is an abstract class.

False

T/F A switch statement in C++ or Java must have a default clause.

False

T/F In C++ and Java, it is possible to create an infinite loop out of while and do loops but not for loops.

False

T/F The type of the reference, not the type of the object, is used to determine which version of a method is invoked in a polymorphic reference.

False

What is a friend function? What is a friend class?

Friend function is allowed to access public, private, or protected data in that class. Friend class can access the "private" and "protected" members of the class in which it is declared as a friend.

From where are Java class instances allocated?

From the heap and accessed through reference variables.

What are the differences between a function and a procedure?

Functions return values based on input and procedures just execute some commands in order

What is multiple inheritance?

If a class has more than one parent class, the process is called multiple inheritance. When a number of classes are related through single inheritance, their relationships to each other can be shown in a derivation tree. The class relationships in a multiple inheritance can be shown in a derivation graph.

What is a nesting class?

If a new class is needed by only one class, there is no reason to define it so it can be seen by other classes. In this situation, the new class can be nested inside the class that uses it. The class in which the new class is nested is called the nesting class.

What are the three semantic models of parameter passing?

In mode: They can receive data from the corresponding actual parameter Out mode: they can transmit data to the actual parameter Inout mode: they can do both

Why does stack-dynamic allocation of local variables support recursion?

In order to support general recursion, a language needs a way to allocate different activation records for different invocations of the same function. That way, local variables allocated in one recursive call can coexist with local variables allocated in a different call.

What is an abstract method? What is an abstract class?

It's a method in the hierarchy of inheritance where only the protocol (not the body) is included in the base class and all the descendants override that method (pure virtual function in C++). An abstract class is a class which has abstract method.

How are local variables locations determined in the run-time stack?

Local variables are pushed on top of the stack frame after return address, dynamic link, and parameters

What is the message protocol of an object?

Message protocol of an object is the entire collection of methods of an object. The entire collection of methods of a class is called the message protocol, or message interface of the class.

What are the legal return types of a constructor?

Neither constructors nor destructors have return types, and neither use return statements. Both constructors and destructors can be explicitly called.

What is a parameter profile? What is a subprogram protocol?

Parameter profile (or signature) of a subprogram contains the number, order, and types of its formal parameters Protocol of a subprogram is its parameter profile plus its return type

What is a dynamic link?

The dynamic link is a pointer to the base of the activation record instance of the caller.

From where can C++ objects be allocated?

The objects of C++ can be static, stack dynamic, or heap dynamic

What is a return address?

The return address is a pointer to the instruction following the call of the calling program unit in the code segment.

T/F C++ provides two constructs, the class and the struct, which support directly abstract data types.

True

T/F C++ supports multiple inheritance, but Java directly supports only single inheritance.

True

T/F In Java, all objects are allocated from the heap and accessed through reference variables.

True

T/F The Environment Pointer (EP) is a variable maintained by the run-time system. It always points at the base of the activation record instance of the currently executing program unit.

True

T/F The binding of actual parameters to formal parameters in C/C++ is by position.

True

T/F The function header void SomeFunc(char arr[]); can be interchangeable with the heading void SomeFunc(char* arr);

True

Describe the three characteristic features of object-oriented languages.

abstract data types, Inheritance and Polymorphism

Consider the following C++ class definitions: class AClass{ private: int a; protected: float b; public: double c; }; class BClass: private AClass{ . . . }; BClass is a private-derived class of AClass. What are the access controls of the inherited data members b, and c in BClass?

b and c are private

Inheritance through class derivation provides support to which of the following concepts?

code reuse

When a method in Java is declared with the __________ modifier, it cannot be overridden in a subclass.

final

Rewrite the following switch statement using an equivalent if-elsestatement. switch (answer) { case 0: System.out.print("0 entered"); break; case 1: System.out.print("1 entered"); break; case 3: System.out.print("3 entered"); break; default: System.out.print("Other value entered");}

if (answer == 0) System.out.print("0 entered"); else if (answer == 1) System.out.print("1 entered"); else if (answer == 3) System.out.print("3 entered"); else System.out.print("Other value entered");

Rewrite the following for-loop statement using an equivalent while-loop statement. for (int j = 1; j <= 100; j++) { System.out.print(j + "\t"); if (j % 5 == 0) System.out.println( ); }

int j = 1; while (j <= 100) { System.out.print(j + "\t"); if (j % 5 == 0) System.out.println( ); j++; }

A continue statement in C/C++ and Java

may be used within any loop statement

A constructor is a method that

performs initialization or setup operations

Individual entities in Java classes have access control modifiers, called visibility modifiers, that are attached to method and variable definitions. These include:

public, private, protected

A class in C++ that includes a _______________ function is an abstract class.

pure virtual

The parameter profile or signature of a subprogram contains

the number, type, and order of parameters.

Given the following C++ declarations. int val = 2; float res = 3.5; Indicate which of the following operations is a narrowing type conversion.

val = res;

What are the values of x, y and z after the execution of the following statements? int x = 3; int y = ++x; int z = x++;

x = 5, y = 4, z = 4

Given the following C++ partial class definition: class A1 { Private: int y; Protected: int z; Public: int x; ... } class A2: public A1 { protected int a; private int b; ... } class A3: public A2 { private int q; ... } Which one of the following options is the list of data members that are accessible in class A3?

x, z, a, q

Consider the following program written in C syntax, what are the values of the list array after the call to fun function? void fun (int& first, int &second) { first += first + second; second += second + first; } int main() { int list [] = {1, 3}; fun(list[0], list[1]); cout << list[0] << " " << list[1] << endl; }

{5, 11}

Consider the following C++ program, what is the output generated in the main function, assuming operands are evaluated left to right in the statement at position 1? int fun (int x, int &y) { ++x; y++; return x; } int main() { int k = 3, j = 11; do { j = j - fun(k, j); //position 1 cout << k <<", "<< j << ", "; } while(++k < 5); return 0; }

3, 7, 4, 2

What is the value of x after executing the following code in C/C++? int x = 3, y = 5, z; z = x; if(x = y) x = y; else if(y > x) x = y % x;

5

Assume that we have the following declarations. int i= 10, j= 4; double m= 2, n= 4; Unary +, unary - (Highest) *, /, % + (add), - (subtract) = (assignment) (Lowest) Using the given table of partial precedence rules, evaluate the following expression, assuming associativity is left to right. i = i % j - i * j / (m - i) + m;

9

What is a polymorphic variable?

A pointer variable that has the type of a base class can be used to point to any heap-dynamic object of any class publicly derived from that base class, making it a polymorphic variable.

What is a virtual method?

A virtual function is a member function which is declared in a base class and is re-defined (Overridden) by a derived class. When you refer to a derived class object using a pointer or a reference to the base class, you can call a virtual function for that object and execute the derived class's version of the function.

What are the advantages and disadvantages of stack-dynamic local variables?

Advantages: flexibility for the subprogram (recursion), share storage with local variables of inactive subprograms Disadvantages: initialization overhead at each call, indirect access, not history sensitive

What are the advantages and disadvantages of static local variables?

Advantages: more efficient access and less allocation overhead Disadvantages: inability to support recursion, inability to share storage with local variables of inactive subprograms

Define abstract data types.

An abstract data type is a data structure, in the form of a record, which includes subprograms that manipulate its data. an abstract data type is an enclosure that includes only the data representation of one specific data type and the subprograms that provide the operations for that type. An instance of an abstract data type is called an object.

What is an overloaded subprogram?

An overloaded subprogram is a subprogram that has the same name as another subprogram in the same referencing environment. Every version of an overloaded subprogram must have a unique protocol.

Given the following class definitions and main function: class Person{ public: virtual double getMoney(){ return 7.25; } }; class Student: public Person{ public: virtual double getMoney(){ return 2.5;} }; class Employee: public Person{ public: virtual double getMoney(){ return 4.5; } }; int main(){ Person * p[3] = {new Student(), new Employee(), new Person()}; for (int i = 0; i < 3; i++ ) { cout << p[i]->getMoney()<< " "; } }

2.5 4.5 7.25

What will be the value of x after the following statements are executed? int x = 12; switch (x) { case 10: x += 15; break; case 12: x -= 5; default: x *= 3; }

21

Using the given table of partial precedence rules and associativity in C++, Highest Postfix ++, postfix -- Left-to-right Unary +, unary -, prefix ++, prefix -- Right-to-left *, /, % Left-to-right + (add), - (subtract) Left-to-right Lowest = (assignment), += Right-to-left What is the value of result assuming that we have the following declarations? int count = 4, result=1; result += -++count * 2;

-9

What is the output of the following code segment? int f = 1; for(int g=4; f < g; g--) { cout << f++ << " " << g << " "; }

1 4 2 3

What are the three general characteristics of subprograms?

1. Each subprogram has a single entry point. 2. The calling program unit is suspended during the execution of the called subprogram, which implies that there is only one subprogram in execution at any given time. 3. Control always returns to the caller when the subprogram execution terminates.

What are the conceptual semantic models of transfer of pass-by-value, pass-by-result, and pass-by-reference parameter passingmethods?

Pass-by-value: the value of the actual parameter is used to initialize the corresponding formal parameter, which then acts as a local variable in the subprogram. it implements in-mode semantics. The advantage of pass-by-value is that for scalars it is fast, in both linkage cost and access time. Pass-by-result: is an implementation model for out-mode parameters. When a parameter is passed by result, no value is transmitted to the subprogram. The corresponding formal parameter acts as a local variable, but just before control is transferred back to the caller, its value is transmitted back to the caller's actual parameter, which obviously must be a variable. Pass-by-reference: is an implementation model for inout-mode parameters. Rather than copying data values back and forth, the pass-by-reference method transmits an access path, usually just an address, to the called subprogram. The advantage of pass- by-reference is that the passing process itself is efficient, in terms of both time and space. Duplicate space is not required and no copying is required.

What are the two kinds of abstractions in programming languages?

Process Abstraction and Data Abstraction

Activating a subprogram requires the dynamic creation of an instance of the activation record for the subprogram. From where storage is allocated for a subprogram activation record instance?

Run-time stack.

What is given in a header of a subprogram?

Specifies that the following syntactic unit is a subprogram definition of some particular kind If the subprogram is not anonymous, the header provides a name for the subprogram It may optionally specify a list of parameters


Related study sets

ادب الصف الثاني ثانوي اسئلة مقالية

View Set

Value is what you get for what you give.

View Set

Chapter 12 - Deliver the customer experience: goods and services via bricks and clicks

View Set

CompTIA Network+ Exam N10-007: Lesson 08

View Set

Unit 3: NCLEX RN DIC, Eclampsia, HELLP, Placental Abruption

View Set

Chapter 9- Motivation, Performance, and Effectiveness

View Set