Visibility Modifier Flashcards

1
Q

Types Of My Modifiers

A

We divide modifiers into two groups:

Access Modifiers - controls the access level

Non-Access Modifiers - do not control access level, but provides other functionality

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

Access Modifiers For clases

A

1.public
The class is accessible by any other class

2.default
The class is only accessible by classes in the same package. This is used when you don’t specify a modifier. You will learn more about packages in the Packages chapter

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

Access modifiers for
[Attributes,Method, Constructor]

A

public
The code is accessible for all classes

2.private
The code is only accessible within the declared class

3.default
The code is only accessible in the same package. This is used when you don’t specify a modifier. You will learn more about packages in the Packages chapter.

4.protected
The code is accessible in the same package and subclasses.

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

Non Access modifiers [For Classes]

A

1.final
The class cannot be inherited by other classes (You will learn more about inheritance in the Inheritance chapter)

2.abstract
The class cannot be used to create objects (To access an abstract class, it must be inherited from another class. You will learn more about inheritance and abstraction in the Inheritance and Abstraction chapters)

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

Non Access modifiers [For attributes and methods, you can use the one of the following]

A

1.final
Attributes and methods cannot be overridden/modified.

2.static
Attributes and methods belongs to the class, rather than an object

3.abstract
Can only be used in an abstract class, and can only be used on methods. The method does not have a body, for example abstract void run();. The body is provided by the subclass (inherited from). You will learn

4.transient
Attributes and methods are skipped when serializing the object containing them

5.synchronized
Methods can only be accessed by one thread at a time.

6.volatile
The value of an attribute is not cached thread-locally, and is always read from the “main memory”

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