Today's Jobs :


CORE JAVA FREQUENTLY ASKED QUESTIONS AND ANSWERS-5


CORE JAVA FREQUENTLY ASKED QUESTIONS AND ANSWERS-5


Question: Can a Byte object be cast to a double value?   
Answer:   No, an object cannot be cast to a primitive value.  
 
Question: What is the difference between a static and a non-static inner class?   
Answer:   A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.  
 
Question: If a variable is declared as private, where may the variable be accessed?   
Answer:   A private variable may only be accessed within the class in which it is declared.  
 
Question: What is an object's lock and which object's have locks?   
Answer:   An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.  
 
Question: What is the % operator?   
Answer:   It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.  
 
Question: When can an object reference be cast to an interface reference?   
Answer:   An object reference be cast to an interface reference when the object implements the referenced interface.  
 
Question: Which class is extended by all other classes?   
Answer:   The Object class is extended by all other classes.  
 
Question: Can an object be garbage collected while it is still reachable?   
Answer:   A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.  
 
Question: Is the ternary operator written x : y ? z or x ? y : z ?   
Answer:   It is written x ? y : z.  
 
Question: How is rounding performed under integer division?   
Answer:   The fractional part of the result is truncated. This is known as rounding toward zero.  
 
Question: What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?   
Answer:   The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.  
 
Question: What classes of exceptions may be caught by a catch clause?   
Answer:   A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.  
 
Question: If a class is declared without any access modifiers, where may the class be accessed?   
Answer:   A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.  
 
Question: Does a class inherit the constructors of its superclass?   
Answer:   A class does not inherit constructors from any of its superclasses.  
 
Question: What is the purpose of the System class?   
Answer:   The purpose of the System class is to provide access to system resources.