Object Oriented Programming interview questions part 45

Object Oriented Programming interview questions part 45

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Which language doesn’t support single level inheritance?

Correct Answer is : All languages support it

2. Output of following program? class A { protected: int a,b; public: void disp() { cout<<a<<b; } }; class B:public A { int x,y; };

Correct Answer is : Compile time error

3. 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); } }

Correct Answer is : B salary is: 4000.0

4. Single level inheritance will be best for___________

Correct Answer is : Inheriting a class which can print all the calculation results

5. Which constructor will be called first from the classes involved in single inheritance from object of derived class?

Correct Answer is : Base class constructor

6. If base class contains 2 nested classes, will it be possible to implement single level inheritance?

Correct Answer is : Yes, always

7. Which among the following best defines static variables members?

Correct Answer is : Data which is common to all the objects of a class

8. Which keyword should be used to declare static variables?

Correct Answer is : static

9. Any changes made to static data member from one member function _____________

Correct Answer is : Is reflected to all the objects of that class

10. Which is the correct syntax for declaring static data member?

Correct Answer is : static dataType memberName;

11. The static data member ______________________

Correct Answer is : Must be defined outside the class

12. The syntax for defining the static data members is:

Correct Answer is : dataType className :: memberName =value;

13. If static data members have to be used inside a class, those member functions _______________

Correct Answer is : Must be static member functions

14. The static data member __________________________

Correct Answer is : Can be accessed using class name if not using static member function

15. Which among the following is correct syntax to access static data member without using member function?

Correct Answer is : className :: staticDataMember;

16. Which data members among the following are static by default?

Correct Answer is : const

17. What is the output of the following program? class Test { private: static int x; public: static void fun() { cout << ++x << “ ”; } }; int Test :: x =20; void main() { Test x; x.fun(); x.fun(); }

Correct Answer is : 21 22

18. Whenever any static data member is declared in a class ______________________

Correct Answer is : Only one copy of the data is created

19. If object of class are created, then the static data members can be accessed ____________

Correct Answer is : Using dot or arrow operator

20. What will be the output of the following program? class Test { public: Test() { cout << "Test's Constructor is Called " << endl; } };   class Result { static Test a; public: Result() { cout << "Result's Constructor is Called " << endl; } };   void main() { Result b; }

Correct Answer is : Result’s Constructor is Called

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon