Member Modifiers (access and nonaccess) Flashcards

Learn all the different modifiers that can be applied to members of classes.

1
Q

What’s the access modifier if you don’t type anything before a class or member?

A

default, which means, package level.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
public class Parent {
   int x = 9;
}
What is the access modifier for x?
A

default, which means, package level.

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

True or False: The subclass Child in a different package from the super class Parent can see the default super class members.

A

FALSE

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

When is visible a default member to a subclass?

A

When the subclass is in the same package than the superclass.

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

Can access modifiers applied to local variables?

A

NO

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

Which is the only modifier that can be applied to a local variable?

A

final

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

Which are the member non access modifiers of Java?

A

static, transient, synchronized, native, strictfp, final and abstract

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

What does final do to a method?

A

I prevents the method from being overriden in a subclass and is often used to enforce the API functionality of a method.

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

Does the code compile?

class SuperClass {
    public final void show () {
       System.out.println ("Anything");
    }
}
class Subclass {
    public void show () {
       System.out.println ("Something else");
    }
}
A

No, trying to override the final method in the super class.

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

What are method arguments?

A

Are the variable declarations that appear in between the parentheses in a method declaration.

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

Can a method argument be declared final?

A

Yes

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

What is an abstract method?

A

The method no contains functional code. It ends with semicolon instead of braces, this is, doesn’t have body.

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

Does the code works?

public class IlegalClass {
    public abstract void doIt ();
}
A

No, it has an error when compiling because with an abstract method the class must be declared abstract.

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

Does the code compiles?

public abstract class LegalClass {
    void goodMethod ( ) {
         // working code
    }
}
A

Yes, an abstract class can have concrete methods.

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

What does concrete class mean?

A

That it’s not abstract.

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

A method can be marked as abstract and final TRUE or FALSE?

17
Q

Can a method be marked as private abstract TRUE or FASLE

18
Q

What’s the opposite modifier to “abstract”?

19
Q

What modifiers prevent that a method may be overriden?

A

final and private

20
Q

If the superclass knows all about the implementation of a certain method it means that the method is?

21
Q

What is the error in:

abstract static void doStuff ();

A

abstract and static cannot be used at the same time

22
Q

Can abstract be used along with static?

23
Q

What is a synchronized method?

A

Indicates that a method can be accessed by only one thread at a time.

24
Q

The modifier syncrhonized can be applied to which elements?

A

Only methods.

25
Which access modifiers can be combined with synchronized?
All of them.
26
What is used for the "native" modifier.
Indicates that a method is implemented in platform-dependent code, often in C.
27
Can native be applied to methods, variables and classes?
No, only methods.
28
What should be the methods body if it's marked as native?
semicolon (;) like abstract.
29
strictfp modifier can be applied to?
classes and methods.
30
What implies strictfp modifier?
forces floating point and floating point operations to adhere to the IEEE 754 standard.
31
Why to mark a class or method with strictfp?
So you can predict how your floating points will be regardless the underlying platform.
32
A variable can be declared strictfp?
No, only methods and classes.