Member Modifiers (access and nonaccess) Flashcards
Learn all the different modifiers that can be applied to members of classes.
What’s the access modifier if you don’t type anything before a class or member?
default, which means, package level.
public class Parent { int x = 9; } What is the access modifier for x?
default, which means, package level.
True or False: The subclass Child in a different package from the super class Parent can see the default super class members.
FALSE
When is visible a default member to a subclass?
When the subclass is in the same package than the superclass.
Can access modifiers applied to local variables?
NO
Which is the only modifier that can be applied to a local variable?
final
Which are the member non access modifiers of Java?
static, transient, synchronized, native, strictfp, final and abstract
What does final do to a method?
I prevents the method from being overriden in a subclass and is often used to enforce the API functionality of a method.
Does the code compile?
class SuperClass { public final void show () { System.out.println ("Anything"); } } class Subclass { public void show () { System.out.println ("Something else"); } }
No, trying to override the final method in the super class.
What are method arguments?
Are the variable declarations that appear in between the parentheses in a method declaration.
Can a method argument be declared final?
Yes
What is an abstract method?
The method no contains functional code. It ends with semicolon instead of braces, this is, doesn’t have body.
Does the code works?
public class IlegalClass { public abstract void doIt (); }
No, it has an error when compiling because with an abstract method the class must be declared abstract.
Does the code compiles?
public abstract class LegalClass { void goodMethod ( ) { // working code } }
Yes, an abstract class can have concrete methods.
What does concrete class mean?
That it’s not abstract.