Modifiers Flashcards
What is an access modifier?
Is a keyword that is used to set the access level for classes, attributes, methods and constructors
Name the modifier groups
Access Modifiers
Non-Access Modifiers
Access Modifiers
Control the access level
Non-Access modifiers
Do not control access level but provide other functionality
Name the class access Modifiers
Public
Default
The public modifier makes the class
Accessible by any other class
The default modifier makes the class
Only accessible by classes in the same package
public, private, default and protected are modifiers for
Attributes, methods and constructors
The private modifier provides access
Only within the declared class
The protected modifier provides access to code
In the same package and subclass
The Non-Access modifiers include
final, abstract, static, transient, synchronized, volatile
The Non-Access modifiers for classes are
final and abstract
Attributes and methods use the following Non-Access modifiers
final, static, abstract, transient, synchronized, volatile
The final modifier for classes means
The class cannot be inherited by other classes
The abstract modifier for classes means
The class cannot be used to create objects
The final modifier on attributes and methods means
Attributes and methods cannot be overridden
The static modifier means
Attributes and methods belong to the class rather than the object
Abstract modifier for methods can
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”);
}
}
The transient method makes
Attributes and methods be skipped when serializing the object containing them
synchronized modifier means
Methods can only be accessed by one thread at a time
volatile modifier means
The value of an attribute is not cached thread-locally and is always read from the main memory