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?

A

FALSE

17
Q

Can a method be marked as private abstract TRUE or FASLE

A

FALSE

18
Q

What’s the opposite modifier to “abstract”?

A

final

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?

A

final

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?

A

NO

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
Q

Which access modifiers can be combined with synchronized?

A

All of them.

26
Q

What is used for the “native” modifier.

A

Indicates that a method is implemented in platform-dependent code, often in C.

27
Q

Can native be applied to methods, variables and classes?

A

No, only methods.

28
Q

What should be the methods body if it’s marked as native?

A

semicolon (;) like abstract.

29
Q

strictfp modifier can be applied to?

A

classes and methods.

30
Q

What implies strictfp modifier?

A

forces floating point and floating point operations to adhere to the IEEE 754 standard.

31
Q

Why to mark a class or method with strictfp?

A

So you can predict how your floating points will be regardless the underlying platform.

32
Q

A variable can be declared strictfp?

A

No, only methods and classes.