Concepts of Programming Chapters 7-14

Ace your homework & exams now with Quizwiz!

What are the differences between the break statement of C++ and that of Java?

In C++, breaks automatically exit the nearest loop; they are unconditional and unlabeled. In Java, you can create a labeled break, which can go to any loop, or cancel that specified loop.

How are C++ heap-​allocated objects deallocated?

Memory for array is allocated by operator new[] and deallocated by operator delete[]. Also note that heap memory for STL containers is managed by the containers' allocator objects, not by new and delete directly.

What is an overriding method?

Method overriding, in object-oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes

What is multiple inheritance?

Multiple Inheritance is a feature of object oriented concept, where a class can inherit properties of more than one parent class. The problem occurs when there exist methods with same signature in both the super classes and subclass. On calling the method, the compiler cannot determine which class method to be called and even on calling which class method gets the priority.

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 two issues that arise when subprogram names are parameters?

(1) Type checking the parameters of the activation of the subprogram that was passed as a parameter. (2) When a subprogram allows nested subprograms, there is sometimes a question as to what referencing environment should be used for executing the pass subprogram.

Are all C++ subclasses subtypes? If so, explain. If not, why not?

No,Privately derived classes are not subtypes in C++. ... Thus when the object of the subclass class is substituted for the object of the base class, it would be illegal to access that data member on subclass object. The IS-A relation is broken here. Thus all subclasses are not subtypes.

Define operator precedence and operator associativity .

Operator precedence are the rules for expression evaluation, which is partially defined by the order, in which the operators of different precedence levels are evaluated. Operator associativity are the rules which handle the order of expression evaluation when operators of the same level of precedence are present. An operator can have left or right associativity. Operator associativity evaluates operators of equivalent precedence in the order in which they occur in the expression, either from left to right, or right to left, depending on whether the program is left or right associative.

What two languages include multiple assignments?

Perl and Ruby

What is the difference between physical and logical concurrency?

Physical concurrency is when it is assumed that if more than one processor is available, several program units from the same program literally execute simultaneously.Logical concurrency is assuming multiple processors can execute simultaneously while the actual execution is taking place in a single processor.

Are all Java subclasses subtypes?

Subclass is not the same as subtype. You might create subclasses that are not subtypes.

Define task, synchronization, competition and cooperation synchronization, liveness, race condition, and deadlock.

Task synchronization is the mechanism that provides the sequence of execution of the different tasks. For example, the task A and task B needs to be executed with the task synchronization task A knows it can only execute only once task B has been Completed. Thus this provides sharing of resources without any problems. Competition is the stare of synchronization where there is usage of resources required by tasks which are not available to all tasks at the same time so in order to attain those resources there is clash between the tasks. Cooperation is the state of synchronization where one or more task depends on another task to be completed for its execution.

Which of the caller or callee saves execution status information?

The last three actions of a call clearly must be done by the caller. Saving the execution status of the caller could be done by either.

What does the range function in Python do?

The range function in Python is used to count loops.

What is a thread of control in a program?

The thread that keeps track of the status of a process in a program.

What are the design issues for exception handling?

1. how exceptions occur, and how they get handled by the exception handler. Unit level, same exception raised at different points. For example if an error is occurred and same error can occur at different point in a program. If an exception is handled it should not handle other parts of exceptions in the rest of the program. The particular block shoould be jandled by exception handler not entire program. 3 - next level user has to identify where exception be thrwon if exceptions are local many handlers are written if excetin are progated the single handle miust hanlde many handlers 4 next issue how exceptions are defined and specidired the exceptions are defined where they are raised in part of a code 5 another is whether andy hardware exceptions can be identified 6 user defined or predefined are temprarily or permanently disabled 7 whether finalizationt is supported by exception hhandling or not

Describe the three characteristic features of object-​oriented languages.

: encapsulation, polymorphism, and inheritance

What is a conditional expression?

A conditional expression evaluates the Boolean value (true or false) of an expression, and does (or doesn't) execute an expression based on those results.

What is the difference between the for statement of C++ and that of Java?

A java for loop is strictly Boolean controlled. C++ for loops can use an arithmetic or Boolean expression to control it.

What is a parameter profile?

A parameter profile contains the number, order, and types of its formal parameters.

What is a polymorphic variable?

A polymorphic Variable is a variable that can reference more than one type of object. Polymorphic variables derive their power from interaction with inheritance, overriding and substituion. A common polymorphic variable is the implicit variable that maintains the reciever during the execution of a method.

What is a prefix operator?

A prefix operator precedes their operands (such as binary operators in Perl)

What is a multithreaded program?

A program that utilizes multiple threads to accomplish its task(s).

What does it mean for an exception to be bound to an exception handler?

A specific exception is to be handled by a specific exception handler also, because different exceptions are to be treated differently.

What is a ternary operator?

A ternary operator has three operands.

How are Java objects deallocated?

All objects are allocated on the heap area managed by the JVM. ... As long as an object is being referenced, the JVM considers it alive. Once an object is no longer referenced and therefore is not reachable by the application code, the garbage collector removes it and reclaims the unused memory.

What is the difference between an activation record and an activation record instance?

An activation record is the format, or layout, of the moncode part of a subprogram, whereas an activation record instance is a concrete example of an activation record, a collection of data in the form of an activation record.

Define exception, exception handler, raising an exception, continuation, finalization, and built- in exception.

An exception is an unusual event which may be erroneous or not and observed by either software or hardware, and which requires special processing An exception handler is a block of code units that is written with the purpose of processing the unusual event raising an exception - When an unusual event occurs, an exception is raised continuation - The question of where to transfer the control after execution of exception handler finalization - In some situations, it is necessary to complete some computation regardless of how subprogram execution terminates. The ability to specify such a computations is called finalization built-in exception - Built-in exception is some of the common predefined exceptions in the language

What is a coercion?

Type checking is a way to ensure that the operands of an operator are compatible. To be of compatible types, the operands must be either legal for the operator type, or allowed to be implicitly converted by the interpreter to a legal type. Coercion is that automatic data type compatibility conversion.

What are the advantages of having support for exception handling built in to a language?

Exception handling have many advantages the most important one is it automatically detects the exception and without using built-in exception handling, the code to detect error condition can be a clutter to the program. Built in exception handling makes our code simplified and easier to see.

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

For example, suppose a program defined a Building class and a collection of subclasses for specific types of buildings, for instance, French_Gothic. It probably would not make sense to have an implemented draw method in Building. But because all of its descendant classes should have such an implemented method, the protocol (but not the body) of that method is included in Building. Such a method is often called an abstract method ( pure virtual method in C++). A class that includes at least one abstract method is called an abstract class (abstract base class in C++).

What are formal parameters? What are actual parameters?

Formal parameters are the declared in the function prototype/definition/subprogram header. Every time the function is called, the formal parameters receive their values when the function is called. Those values that are passed when the function is called are called actual parameters. The values of actual parameters are copied to the formal parameters whenever the function call is made.

What is a heavyweight task? What is a lightweight task?

Heavyweight task is identified as those processes which uses its own individual address space and execution stack. Lightweight task are those processes which utilizes shared address space and execution stack.

What are two fundamental design considerations for parameter-​passing methods?

Efficiency and the directionality of data transfer. One-way parameters are more secure and reliable, but the two-way pass-by-reference is more efficient.

Why are the return address, dynamic link, and parameters placed in the bottom of the activation record?

because the entry must appear first.

What is an overloaded operator?

An overloaded operator is a special case of polymorphism where an operator has different implementations depending on their arguments.

What is boxing?

Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type. When the common language runtime (CLR) boxes a value type, it wraps the value inside a System. Object instance and stores it on the managed heap. ... Boxing is implicit; unboxing is explicit.

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

Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block. Instance variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed.

Describe a situation where dynamic binding is a great advantage over static binding.

Consider the following situation: There is a base class, A, that defines a method draw that draws some figure associated with the base class. A second class, B, is defined as a subclass of A. Objects of this new class also need a draw method that is like that provided by A but a bit different because the subclass objects are slightly different. So, the subclass overrides the inherited draw method. If a client of A and B has a variable that is a reference to class A's objects, that reference also could point at class B's objects, making it a polymorphic reference. If the method draw, which is defined in both classes, is called through the polymorphic reference, the run-time system must determine, during execution, which method should be called, A's or B's.

From where can Java objects be allocated?

In Java, all objects are dynamically allocated on Heap. This is different from C++ where objects can be allocated memory either on Stack or on Heap. In C++, when we allocate the object using new(), the object is allocated on Heap, otherwise on Stack if not global or static.

What is one possible disadvantage of treating the assignment operator as if it were an arithmetic operator?

In an arithmetic operator, assignment operators have a different (lower) priority than any other arithmetic operator. Their presence in an arithmetic expression can make the expression hard to understand, and lead to a problem of expression side effect.

What is the task of a linker?

In computing, a linker or link editor is a computer system program that takes one or more object files (generated by a compiler or an assembler) and combines them into a single executable file, library file, or another "object" file.

What is a virtual method?

In object-oriented programming, in languages such as C++, and Object Pascal, a virtual function or virtual method is an inheritable and overridable function or method for which dynamic dispatch is facilitated. This concept is an important part of the polymorphism portion of object-oriented programming

What are the three possible levels of concurrency in programs?

Instruction level, Statement level, and Unit level

7. What are the differences between a function and a procedure?

Procedures are used to define new statements, and functions define new operators that are defined by the user. Functions return values, but procedures do not.

What is unusual about Python's design of compound statements?

Python relies on indentation to specify compound statements. Anything equally indented belongs to the same/one group.

8. Describe the problem of passing multi-dimensioned arrays as parameters.

Since they are arrays of arrays, the numbers of columns must be specified in languages like C. Because of this, pointers to the multidimensional array are usually used instead.

Compare the efficiency of the deep-​access method to that of the shallow-​access method, in terms of both calls and nonlocal accesses.

The deep access methods provides fast subprogram linkage, but references to nonlocal, especially references to distant nonlocals (in term of the call chain), are costly. The shallow access methods provide much faster references to nonlocals, especially distant nonlocals, but are more costly in term of subprogram linkage.

What causes a C++ template function to be instantiated?

The first time a function template is called, the compiler creates an instantiation. Every time a different type is called for the first time, a new instantiation is created for that type. The instantiation of that type will be used every time a function of the same type is called.

In what way is C's for statement more flexible than that of many other languages?

The for loop in C is more flexible than most languages because it can be made up of multiple expressions, allowing for multiple loop variables of varying types.

How does a functional language implement repetition? How does it differ from the implementation of repetition in imperative languages?

The function language

What must be stored for the linkage to a subprogram?

What must be stored for the linkage to a subprogram? ... Then, the linker must set the target addresses of all calls to those subprograms in the main program to the entry addresses of those subprograms.


Related study sets

14. The Watsons Go to Birmingham Vocabulary - Chapter 14

View Set

Psychology 101 Chapter 9: The Knowing Mind - Memory

View Set

Chapter 8, Section 3- Spanish American War (foldable questions)

View Set

The use of a glossary suggest which of the following?

View Set

Fluid &Electrolyte/Acid-Base Imbalances

View Set