| Snaprecruit.com

| Snaprecruit.com

Interview question based on skill :

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

Total Questions: 20

1. If protected inheritance is used then _____

Correct Answer is : Protected and Public members become protected in subclass

2. If protected members are to be accessed from outside the class then__________

Correct Answer is : Members must be made public

3. Which among the following can use protected access specifier?

Correct Answer is : Members which have to be secure and should be used by other packages/subclass

4. Protected access is same as default access that is given implicitly in java if no specifier is mentioned.

Correct Answer is : FALSE

5. If a class have default constructor defined in private access, and one parameter constructor in protected mode, how will it be possible to create instance of object?

Correct Answer is : Define a constructor in public access with different signature

6. What will be the output of the program given below: class A { Public : A(int a=0) { cout<<”new A”; } }; A a; A b; A c;

Correct Answer is : new Anew Anew A

7. Which among the following is true for the code given below: class A { int marks; public : disp() { cout<<marks; } } class B: protected A { char name[20]; } A a; a.disp(); B b; b.disp();

Correct Answer is : Only object of class A can access disp() function

8. If the members have to be accessed from anywhere in program and other packages also, which access specifier should be used?

Correct Answer is : Public

9. Which among the following have least security according to the access permissions allowed?

Correct Answer is : Public

10. Which among the following can be used for outermost class access specifier in java?

Correct Answer is : Default or Public

11. We can reduce the visibility of inherited methods.

Correct Answer is : FALSE

12. If members of a super class are public, then________

Correct Answer is : All those will be available in subclasses

13. How many public class(s) (outermost) can be there in a java program?

Correct Answer is : 1

14. What is output of following code? package pack1; class A { public A() { System.out.print(“object created”); } } package pack2; import pack1.*; class B { A a=new A(); }

Correct Answer is : Compile time error

15. Which among the following for public specifier is false?

Correct Answer is : The static members can’t be public

16. A class has its default constructor defined as public. Class B inherits class A privately. The class:

Correct Answer is : Both classes can have instances

17. Which specifier can be used to inherit protected members as protected in subclass but public as public in subclass?

Correct Answer is : Public

18. Which among the following is true for public class?

Correct Answer is : Public classes can be accessed from any other class using instance

19. If a class doesn’t have public members, then________

Correct Answer is : None of its member function can be called outside the class

20. In multi-level inheritance(all public) , the public members of parent/superclass will ________

Correct Answer is : Will continue to get inherited subsequently