Object Oriented Programming interview questions part 41

Object Oriented Programming interview questions part 41

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

Total Questions: 20

1. If private member functions are to be declared in C++ then _____________

Correct Answer is : private:

2. In java, which rule must be followed?

Correct Answer is : Keyword private preceding each private member

3. How many private member functions are allowed in a class ?

Correct Answer is : As many as required

4. How to access a private member function of a class?

Correct Answer is : Using address of member function

5. Private member functions ____________

Correct Answer is : Can’t be called from enclosing class

6. Which function among the following can’t be accessed outside the class in java in same package?

Correct Answer is : protected show()

7. If private members are to be called outside the class, which is a good alternative?

Correct Answer is : Call a public member function which calls private function

8. A private function of a derived class can be accessed by the parent class.

Correct Answer is : FALSE

9. Which error will be produced if private members are accessed?

Correct Answer is : Can’t access private message

10. Can main() function be made private?

Correct Answer is : No, never

11. If a function in java is declared private then it __________________

Correct Answer is : Can access the standard output

12. Which among the following best describes the protected specifier?

Correct Answer is : Members are secure as private, but can be inherited

13. If a constructor is defined in protected access, then.

Correct Answer is : It’s instance can be created inside the subclasses

14. For the following code, choose the correct option: class A { int marks; protected : A() { marks=100; } public : A( int x) { marks=x; } };

Correct Answer is : The instances can be created anywhere in the program

15. If the protected members are to be made accessible only to the nearest subclass and no further subclasses, which access specifier should be used in inheritance?

Correct Answer is : The sub class should inherit the parent class privately

16. What will be the output of following code (all header files and required things are included)? class A { int marks; protected : A(int x) { marks=x; } public : A() { marks=100; } } class B { A a; A b=100; }; main() { A a, b=100; B c; }

Correct Answer is : Program gives compile time error

17. Which among the following is true for the given code below. class A { protected : int marks; public : A() { marks=100; } disp() { cout<<”marks=”<<marks; } }; class B: protected A { }; B b; b.disp();

Correct Answer is : Object b can’t access disp() function

18. Protected members differ from default members as_______

Correct Answer is : Protected members can be accessed outside package using inheritance, but default can’t

19. If all the members are defined in protected specifier then ( Constructors not considered ):

Correct Answer is : Instance of class can be created anywhere

20. Which among the following is correct for the code given. class A { private: int marks; A() { } Public : disp() { cout<< marks; } }; class B: public A { } B b;

Correct Answer is : Instance of B will not be created

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon