Chapter 5: Methods Flashcards

1
Q

A final instance variable in Java 17 can be assigned multiple times. True or False? If false, why?

A

False – A final instance variable can only be assigned once: in the declaration, an instance initializer, or a constructor.

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

Both instance and static initializers can access static variables in Java 17. True or False?

A

True

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

A static initializer in Java 17 can access instance variables. True or False? If false, why?

A

False – A static initializer cannot access instance variables because it runs before any instance is created.

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

An instance initializer in Java 17 can assign a final instance variable. True or False? If false, why?

A

True

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

A final instance variable in Java 17 must always be initialized at the time of declaration. True or False? If false, why?

A

False – It can also be initialized in an instance initializer or a constructor.

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

A method signature in Java 17 includes the method name and parameter list. True or False? If false, why?

A

True

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

The return type is part of the method signature in Java 17. True or False? If false, why?

A

False – The method signature includes only the method name and parameter list, not the return type.

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

The access modifier of a method is required in Java 17. True or False? If false, why?

A

False – The access modifier is optional; a method can have default access.

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

A method in Java 17 must always have an exception list. True or False? If false, why?

A

False – The exception list is optional; methods are not required to declare exceptions.

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

A method in Java 17 can have an empty parameter list. True or False? If false, why?

A

True

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

Abstract methods in Java 17 must have a method body. True or False? If false, why?

A

False – Abstract methods cannot have a body; they are meant to be implemented by subclasses.

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

The method body is always required for all methods in Java 17. True or False? If false, why?

A

False – Abstract methods do not require a method body.

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

Optional specifiers like final and static are required in Java 17 method declarations. True or False? If false, why?

A

False – Optional specifiers are not required; methods can be declared without them.

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

A method declaration in Java 17 includes all necessary details to call the method. True or False? If false, why?

A

True

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

In Java 17, an access modifier controls where the method can be referenced. True or False? If false, why?

A

True

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