Question: What does it mean that a class or member is final?
Answer: A final class can no longer be subclassed. Mostly this is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve.
Methods may be declared final as well. This means they may not be overridden in a subclass.
Fields can be declared final, too. However, this has a completely different meaning. A final field cannot be changed after it's initialized, and it must include an initializer statement where it's declared. For example,
public final double c = 2.998;
It's also possible to make a static field final to get the effect of C++'s const statement or some uses of C's #define, e.g.
public static final double c = 2.998;
Question: What does it mean that a method or class is abstract?
Answer: An abstract class cannot be instantiated. Only its subclasses can be instantiated. You indicate that a class is abstract with the abstract keyword like this:
public abstract class Container extends Component {
Abstract classes may contain abstract methods. A method declared abstract is not actually implemented in the current class. It exists only to be overridden in subclasses. It has no body. For example,
public abstract float price();
Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do.
Each subclass of an abstract class must override the abstract methods of its superclasses or itself be declared abstract.
Question: what is a transient variable?
Answer: transient variable is a variable that may not be serialized.
Question: How are Observer and Observable used?
Answer: Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.
Question: Can a lock be acquired on a class?
Answer: Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.
Question: What state does a thread enter when it terminates its processing?
Answer: When a thread terminates its processing, it enters the dead state.
Question: How does Java handle integer overflows and underflows?
Answer: It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
0 comments:
Post a Comment