0% found this document useful (0 votes)
10 views

Class 10 Practice 6

The document contains a series of questions and answers related to access modifiers in Java, covering their definitions, visibility, and usage. Key concepts include the different types of access modifiers (public, private, protected, default), their restrictions, and how they affect class members. It also addresses the inheritance and accessibility of class members based on their access specifiers.

Uploaded by

ayanacharya2009
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Class 10 Practice 6

The document contains a series of questions and answers related to access modifiers in Java, covering their definitions, visibility, and usage. Key concepts include the different types of access modifiers (public, private, protected, default), their restrictions, and how they affect class members. It also addresses the inheritance and accessibility of class members based on their access specifiers.

Uploaded by

ayanacharya2009
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1) What is an access modifier in Java?

a) An access modifier controls the visibility of variables, constants and methods of a class
b) An access modifier can hide or show a variable or method to outside classes.
c) Access modifiers help in implementing the Encapsulation feature of OOPs.
d) All the above

2) Which is the keyword used to specify the DEFAULT access modifier in java?
a) default
b) auto
c) normal
d) There is no keyword

3) Which is the less restrictive access modifier in Java?


a) public
b) private
c) protected
d) default

4) Which is the most restrictive access modifier in Java?


a) public
b) private
c) protected
d) default

5) Is it possible to combine more than one access modifier in Java?


a) No
b) Yes

6) Which of these access specifiers must be used for main() method?


a) private
b) public
c) protected
d) none of the mentioned

7) Which of these is used to access a member of class before object of that class is created?
a) public
b) private
c) static
d) protected

8) Which of these is used as a default for a member of a class if no access specifier is used for it?
a) private
b) public
c) public, within its own package
d) protected

9) What is the process by which we can control what parts of a program can access the
members of a class?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion

10) Which of the following statements are incorrect?


a) public members of class can be accessed by any code in the program
b) private members of class can only be accessed by other members of the class
c) private members of class can be inherited by a subclass, and become protected members
in subclass
d) protected members of a class can be inherited by a subclass, and become private
members of the subclass

11) Which of these access specifier must be used so that it can be inherited by another subclass?
a) public
b) private
c) protected
d) none of the mentioned

12) The private member of a class can be accessible


a) Within the class in which it is declared
b) Within all the sub-classes of its class in any package where this class is visible
c) Within all the classes in the package containing its class
d) None of the above

13) The protected member of a class can be accessible


a) Within all the sub-classes in any package.
b) Within all the classes in the package containing its class
c) Within all the classes in any other package
d) both a and b

14) The public member of a class can be accessible


a) Within the class in which it is declared
b) Within the package containing its class
c) Other packages where this class is visible
d) All of the above

15) Can you access a default member of a class from a class outside the current package?
a) No
b) Yes

16) Choose the correct statement about access modifiers in Java.


a) public, protected and default variables and methods can be accessed outside the package
somehow.
b) public and protected variables and methods can be accessed outside the package
somehow.
c) Only public variables and methods can be accessed outside the package somehow.
d) None of the above

17) To access a protected variable or method of a Class outside the package, you need to.
a) Create an instance and call the protected variable or method
b) Create a Subclass and call the protected variable or method
c) A and B
d) None of the above

18) Choose the correct Java code snippet with access modifiers below?
a) class ABC { }
b) private protected class ABC { }
c) protected public class ABC { }
d) protected private class ABC { }

19) Visible in the classes and subclasses in the same package and subclasses in other packages.
a) private
b) public
c) protected
d) default

20) The ________ access specifier used in a class cannot be accessed by subclass in the same
package.
a) private
b) public
c) protected
d) default

You might also like