1 Flashcards
(70 cards)
What do access level modifiers determine?
They determine whether other classes can use a particular field or invoke a particular method.
What does the public access modifier do?
Members are accessible by everyone.
What does the private access modifier do?
Members are only accessible from within the class.
What does the protected access modifier do?
Accessible from within the class, within its subclasses, and within classes from the same package.
What is the default access level if no modifier is stated?
Package-private level access.
What does the final keyword do when declaring a variable?
Prevents its value from being changed.
What happens to an object’s reference when declared as final?
The variable cannot be made to refer to a different object after the declaration.
What happens to the state of an object declared as final?
The state of the object can change.
What is the effect of a final method?
It cannot be overridden.
What is the effect of a final class?
It cannot be extended.
What is a static field?
A field that belongs to the class instead of each instance having its own.
How do you access a static field or method?
Use the class name.
What do static and final combined create?
A constant.
What can interfaces specify?
A list of required methods to be implemented.
What does decoupling mean in the context of interfaces?
Separation of the interface from the implementation.
Why use interfaces?
Enable and enforce strict sharing of methods among classes and make code more reusable.
What can an interface contain?
Method signatures, default methods, static methods, and nested types.
What is the difference between class inheritance and interface inheritance?
Class inheritance uses ‘extends’ while interface inheritance uses ‘implements’.
What is one of the main characteristics of an interface?
It cannot have a constructor or any instance fields.
What is an abstract class?
A cross between a regular class and an interface.
What must any abstract method use?
The abstract keyword.
Can an abstract class be instantiated?
No, it cannot be instantiated even if it has a constructor.
When should you consider using abstract classes?
When code needs to be shared among closely related classes.
When should you consider using interfaces?
When unrelated classes would implement the interface.