A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

41. Output of following program?
class A
{
 protected: int a,b;
 public: void disp()
 { 
  cout<<a<<b; 
 }
};
class B:public A
{
 int x,y;
};
a. Garbage value
b. Compile time error
c. Runtime error
d. Runs but gives random values as output
View Answer Report Discuss Too Difficult!
Answer: (b).Compile time error

42. Output of following program?
class A
{  
 float sal=40000;  
}  
class B extends A
{  
 int salBonus=10000;  
 public static void main(String args[])
 {  
  B p=new B();  
  System.out.println("B salary is:"+p.sal);  
  System.out.println("Bonus of B is:"+p.bonus);  
 }  
}
a. B salary is: 4000.0
Bonus of B is: 10000
b. B salary is 10000
Bonus of B is: 4000.0
c. Compile time error
d. Runtime error
View Answer Report Discuss Too Difficult!
Answer: (a).B salary is: 4000.0
Bonus of B is: 10000

43. Single level inheritance will be best for___________
a. Inheriting a class which performs all the calculations
b. Inheriting a class which can print all the calculation results
c. Inheriting a class which can perform and print all calculations
d. Inheriting all the classes for different calculations
View Answer Report Discuss Too Difficult!
Answer: (b).Inheriting a class which can print all the calculation results

44. Which constructor will be called first from the classes involved in single inheritance from object of derived class?
a. Base class constructor
b. Derived class constructor
c. Both class constructors at a time
d. Runtime error
View Answer Report Discuss Too Difficult!
Answer: (a).Base class constructor

45. If base class contains 2 nested classes, will it be possible to implement single level inheritance?
a. Yes, always
b. Yes, only if derived class also have nested classes
c. No, it will use more than 2 classes which is wrong
d. No, never
View Answer Report Discuss Too Difficult!
Answer: (a).Yes, always

46. Which among the following best defines multilevel inheritance?
a. A class derived from another derived class
b. Classes being derived from other derived classes
c. Continuing single level inheritance
d. Class which have more than one parent
View Answer Report Discuss Too Difficult!
Answer: (b).Classes being derived from other derived classes

47. If there are 5 classes, E is derived from D, D from C, C from B and B from A. Which class constructor will be called first if the object of E or D is created?
a. A
b. B
c. C
d. A and B
View Answer Report Discuss Too Difficult!
Answer: (a).A

48. If there are 3 classes. Class C is derived from class B and B is derived from A, Which class destructor will be called at last if object of C is destroyed.
a. A
b. B
c. C
d. All together
View Answer Report Discuss Too Difficult!
Answer: (a).A

49. Which Class is having highest degree of abstraction in multilevel inheritance of 5 levels?
a. Class at 1st level
b. Class 2nd last level
c. Class at 5th level
d. All with same abstraction
View Answer Report Discuss Too Difficult!
Answer: (a).Class at 1st level

50. If all the classes use private inheritance in multilevel inheritance then ______________
a. It will not be called multilevel inheritance
b. Each class can access only non-private members of its parent
c. Each subsequent class can access all members of previous level parent classes
d. None of the members will be available to any other class
View Answer Report Discuss Too Difficult!
Answer: (b).Each class can access only non-private members of its parent

Page 5 of 11