Modifiers Flashcards

1
Q

What is an access modifier?

A

Is a keyword that is used to set the access level for classes, attributes, methods and constructors

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

Name the modifier groups

A

Access Modifiers
Non-Access Modifiers

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

Access Modifiers

A

Control the access level

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

Non-Access modifiers

A

Do not control access level but provide other functionality

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

Name the class access Modifiers

A

Public
Default

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

The public modifier makes the class

A

Accessible by any other class

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

The default modifier makes the class

A

Only accessible by classes in the same package

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

public, private, default and protected are modifiers for

A

Attributes, methods and constructors

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

The private modifier provides access

A

Only within the declared class

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

The protected modifier provides access to code

A

In the same package and subclass

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

The Non-Access modifiers include

A

final, abstract, static, transient, synchronized, volatile

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

The Non-Access modifiers for classes are

A

final and abstract

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

Attributes and methods use the following Non-Access modifiers

A

final, static, abstract, transient, synchronized, volatile

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

The final modifier for classes means

A

The class cannot be inherited by other classes

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

The abstract modifier for classes means

A

The class cannot be used to create objects

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

The final modifier on attributes and methods means

A

Attributes and methods cannot be overridden

17
Q

The static modifier means

A

Attributes and methods belong to the class rather than the object

18
Q

Abstract modifier for methods can

A

Only be used on a body-less method where the body is provided by the subclass. Eg

abstract class Modi {
public String first = “Yoki”;
public int age = 24;
public abstract void study();
}

class Student extends Modi {
public int gyear = 2024;
public abstract void study() {
System.out.println(“Study hard”);
}
}

19
Q

The transient method makes

A

Attributes and methods be skipped when serializing the object containing them

20
Q

synchronized modifier means

A

Methods can only be accessed by one thread at a time

21
Q

volatile modifier means

A

The value of an attribute is not cached thread-locally and is always read from the main memory