Monday, March 26, 2012

Basic Java Interview Questions & Answers



1) Which statement(s) declare an array of string objects?

String[] s

String []s

String[ s]

String []s

2) Which of the following is true about constructor and method ?

Constructor have its own name,and return type, innvoked using new operator

Function has its own name, a return type and is invoked using the dot operator

Constructor has name of class and no return type, and is innvoked using new operator

3) Basic I/O is performed by which class?

Security Manager

Math

Run time

System

None of these above

3 ) An example of polymorphism :

Inner Class

Method Over Loading

Method over ridding

annonymouse class

4) Which is primitive type :

byte

String

Float

5) 1.4.56+ "1.2" returns

String 5.76

Long 5

Double 5.76

String "4.561.2"

6) Asssuming that we have not provided any arguments on the command line, the first element of the string array in the main method contains:

The name of the programe

null

empty

the input for the program

7) How do you implement polymorphism in java?

Method over loading

Method over overridding through the java inter faces

Method over overridding through inheritance

8) What is the output of the following code
int arrayint[][]=new int[10][20]
int arrayint1[][]={{1,2},{1,4},{6,5}}

10 & 3

20 & 2

20 & 3

20 & 6

9) consider the following code sample
if(a!=null&&a.length()>0){ ...}
what will happen if replace && with &?

Logical error

Null pointer exception

There is no output

None of the above

10) there are two classes class A and class B. If class A what to inform B some important information it uses which of the following method(s)

notify(),notifyall(),wait()

notify(),notifyall()

notifyall(),wait()

None of the above

11) when do we get a default constructor

When the class has no other constructor

When we define at least one constructor

When we define a class

None of the above

12) which of the following will output -6?

System.out.println(Math.floor(-6.7))

System.out.println(Math.ceil(-6.7))

System.out.println(Math.Min(-6.7))

System.out.println(Math.round(-6.7))

13) Which of the following are methods of math class

Absolute()

log()

cosine()

sine()

None of the above

14) when two or more objects are added as listeners of the same event,which listerner will inovked first to handle the event?

First object that was added as listener

Last object that was added as listener

There is no way to determine which listener will be invoked first

it is impossible to have more than one listener for a given event

15) character literals are stored as unicode characters :

true

False







please correct me if i am make any mistake :(