...
Question 9980 – Operating-Systems
December 14, 2023
Question 9784 – GATE 2001
December 14, 2023
Question 9980 – Operating-Systems
December 14, 2023
Question 9784 – GATE 2001
December 14, 2023

Programming

Question 41

Consider the following class definitions in a hypothetical Object Oriented language that supports inheritance and uses dynamic binding. The language should not be assumed to be either Java or C++, though the syntax is similar.

Class P {
    void f(int i) {
        print(i);
    }
}

Class Q subclass of P {
    void f(int i) {
        print(2*i);
    }
} 

Now consider the following program fragment:

Px = new Q();
Qy = new Q();
Pz = new Q();
x.f(1); ((P)y).f(1); z.f(1); 

Here ((P)y) denotes a typecast of y to P. The output produced by executing the above program fragment will be

A
1 2 1
B
2 1 1
C
2 1 2
D
2 2 2
Question 41 Explanation: 
Because of using dynamic binding it results a values such as 2 2 2.
Note: The given question is not in the present syllabus
Correct Answer: D
Question 41 Explanation: 
Because of using dynamic binding it results a values such as 2 2 2.
Note: The given question is not in the present syllabus
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!