Adsnese

Ad

Tuesday, September 16, 2008

Core Java Interview Questions Part-4

46 Q What is the difference between readers and streams?

Readers are character oriented where streams are byte oriented. The readers are having full support for Unicode data.

47 Q What is constructor chaining ?

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 ?

There are 8 primitive types in java. boolean , char, byte, short, int long, float, double.

49 Q What is static ?

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?

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 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?

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 ?

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 ?

Overloading methods must differ in their parameter list, or number of parameters.

55 Q What is casting ?

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 ?

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 void indicates that the method will not return anything.

58 Q What will happen if an exception is not caught ?

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?

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?

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.

No comments:

My Ad

.