|
|
Core Java Interview Questions |
|
|
| 46 |
Q |
What is the difference between readers and streams? |
|
A |
Readers are character oriented where streams are byte oriented.
The readers are having full support for Unicode data. |
|
|
| 47 |
Q |
What is constructor chaining ? |
|
A |
When a constructor of a class is executed it will automatically call the
default constructor of the super class (if no explicit call to any of the
super class constructor) till the root of the hierarchy. |
|
|
|
| 48 |
Q |
What are the different primitive data type in java ? |
|
A |
There are 8 primitive types in java. boolean , char, byte, short, int
long, float, double. |
|
|
|
| 49 |
Q |
What is static ? |
| |
A |
static means one per class. static variables are created when the
class loads. They are associated with the class. In order to access
a static we don't need objects. We can directly access static methods and
variable by calling classname.variablename. |
|
|
|
| 50 |
Q |
Why we cannot override static methods? |
|
A |
Static means they are associated with a class. In static methods , the
binding mechanism is static binding. So it must be available at the compile
time. |
|
|
|
| 51 |
Q |
What is the difference between static and non
static variables ? |
|
A |
A static variable is associated with the
class as a whole rather than with specific instances of a class. There will
be only one value for static variable for all instances of that class. Non-static
variables take on unique values with each object instance. |
|
|
|
| 52 |
Q |
When does a compiler supplies a default
constructor for a class? |
|
A |
If there is no other constructor exist in a
class, the compiler will supply a default constructor. |
|
|
|
| 53 |
Q |
What are the restrictions placed on overriding
a method ? |
|
A |
The overridden method have the exact signature of the super
class method, including the return type. The access specified cannot be less
restrictive than the super class method. We cannot throw any new exceptions
in overridden method. |
|
|
|
| 54 |
Q |
What are the restrictions placed on overloading
a method ? |
|
A |
Overloading methods must differ in their parameter list,
or number of parameters. |
|
|
|
| 55 |
Q |
What is casting ? |
|
A |
Casting means converting one type to another. There are
mainly two types of casting. Casting between primitive types and casting
between object references. Casting between primitive numeric types is used
to convert larger data types to smaller data types. Casting between object references is used to refer to an object by a
compatible class, interface, or array type reference. |
|
|
|
| 56 |
Q |
What is the difference between == and equals ? |
|
A |
The equals method can be considered to perform a deep
comparison of the value of an object, whereas the == operator performs a
shallow comparison. If we are not overriding the equals method both
will give the same result. == will is used to compare the object references.
It is used to check whether two objects are points to the same reference. |
|
|
|
| 57 |
Q |
What is a void return type ? |
|
A |
A void indicates that the method will not
return anything. |
|
|
|
| 58 |
Q |
What will happen if an exception is not caught ? |
|
A |
An uncaught exception results in the uncaughtException()
method of the thread's ThreadGroup, which results in the termination of the
program. |
|
|
|
| 59 |
Q |
What are the different ways in which a thread can enter
into waiting state? |
|
A |
There are three ways for a thread to enter into waiting
state. By invoking its sleep() method, by blocking on I/O, by unsuccessfully
attempting to acquire an object's lock, or by invoking an object's wait()
method. |
|
|
|
| 60 |
Q |
What is a ResourceBundle class? |
| |
A |
The ResourceBundle class is used to store locale-specific
resources that can be loaded by a program to create the program's appearance
to the particular locale in which it is being run. |
|
|
|
|
|
|