Java Access Modifiers Flashcards

1
Q

Access levels affect you in two ways. First, when you use classes that come from another source, such as the classes in the Java platform, access levels determine which m_________ of those classes your own classes can use.
Second, when you write a class, you need to decide what access level every member variable and every method in your class should have.

A

members

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Public/package-private - Class

A class will either have a ‘public’ modifier and be visible e____________,
e.g. public class Dog {

or it won’t have a modifier meaning that it (the default, also known as p_____-p_______), is visible only within its own package’
e.g. class Dog {

A

everywhere
package-private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Public/Private/Protected - Members (variables, methods)

There are three access modifiers that can be used for m_______ of a Java class.

1) Public
= a public member can be accessed by everything, everywhere

2) Private
= Private members can only be accessed in their own c________

3) Protected
= A protected member can only be accessed within its own p_______ and by a s_______ of its class in another package.

A

members
class
package
subclass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Default Package S______

If there is no modifier then we are using the default, also known as package-private, it is visible only within its own package

A

scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly