Questions and Answers to Java Test (Recalled from the Certification Exam)

Test Questions recalled Date of Exam : 07/02/00

1. Float a = new Float(10.0F);

Float b = new Float(10.0F);

Long c = new Long(10L);

which one is true

a) a == b

b) a.equals(b)

c) a.equals(c)

d) a.equals(new Float(10.0F))

Answer: B & D

2. From given code, which are possible values for 'a' to print "test2" in output

if (a >4)

System.out.println("test1");

Else if (a >9)

System.out.println("test2");

Else

System.out.println("test3");

a.less than 0

b.less than 4

c.between 4 and 9

d.greater than 9

e.none

Answer: E

3. Choose the correct sentence for fully encapsulated class

a.All member variables are private

b.All member variables declared private and provide

public accessor methods for each variable.

c.Declare all variables without any access modifier.

e.Make all the methods private

Answer: B

4.You have a method in a class whose implementation you don't

want to change although you want to allow the class to be inherited

and used freely. What keyword would u use in the method declaration?

Answer: final

5.Choose correct declarations of two dimensional String array

a.String[][] a = String[20][20]

b.String[][] a = new String[20,20]

c.String[][] a = new String[20][20]

d.String a[][] = new String[20][20]

e.String[] a[] = new String[20]20]

Answer: C,D & E

6.Quesion on identifiers like Choose Correct identifiers

a.thisString

b.%var

c._toString

d._4_

Answer : A,C & D

7.choose the correct statement about gridbag layout

a.The weightx & weighty should have values between 0.0 & 1.0

b.If you specify the fill field is BOTH, there is no meaaning to set anchor field

c.If you specify anchoe field there is no meaning to set fill field is BOTH

Like this

Ans A

8.A question on Garbage collecting like it wiil ask you where the particlular

object exactly available to garbage collection

after line3

after line4

after line5

like this

9.What is the return type of main function which is the starting point of class

Ans void

10.Choose the Java key words from below

a.NULL

b.sizeof

c.extends

d.synchronized

Answer : C & D

11.Employee is a person. Employee has some info stored in vector,

no. of dependants, a flag tells is he IT asesse or not

Write a primary declaration for employee class by using the below words

public

Person

Employee

Vector

Boolean

int

class

extends

Ans : public class Employee extends Person

12.FilterInputStream is base class for BufferedInputStream and DataInputStream.

Choose the correct one which is the correct argument for the FilterInputStream

a.file

b.OutputStream

c.RandomAccessFile

d.InputStream

Answer : D

13.If you want to make your component to activate for user events,

choose the statements which are correct

a.you can add listener interfaces to this component

b.If you add multiple listeners they will become friendly to each other

c.You can add multiple interfaces to the component for different events

d.If listeners added, user can choose and implement only those methods what he needs

e.The component which is derived from awt.component is not listen the events for it self.

Answer : A,C

14.Choose the correct one about thread

a.The threads from one class ends at same time

b.when JVM exits the main method, it will stop only after all the threads are stopped.

c.If there are multiple threads , reading or writing of data of class is inconsistant

d.Programmer has to write a special programe for garbage collection in multiple threads

Answer B & C

 

 

15. Parent p = new Parent();

Child1 c1 = new Child1();

Child2 c2 = new Child2();

Child1 s = (Child1) new Parent;

Which one is correct

a)legal at compile time but illegal at runtime

b)illegal at compile time and runtime

c)illegal at compile time but legal at runtime

d)legal at compile time and runtime

Answer : A

16.Which one is valid for declaring the automatic variable

(method local variables)

public

final

static

Answer: final

17.which is java modifier to use method declaration

prevents to use 'this' in the method

Answer: static

18 from given code, which are possible values for 'a' to print

"test3" in output

if (a >4)

System.out.println("test1");

Else if (a >9)

System.out.println("test2");

Else

System.out.println("test3");

a.less than 0

b.less than 4

c.between 4 and 9

d.greater than 9

e.none

Answer : B

19. Range of the int

 

20. Range of the char

21. Parameters for main method in Java :

Answer : String [] arv

22. Interface with out order, duplicate and with out any search key.

: Set

23.

Public class MyClass{

Float x, float y;

Int z;

public MyClass(float a, float b)

{

x= a;

y=b;

}

public MyClass(float a,float b, int c)

{

// write code to do what MyClass (float a,float b ) is doing

z =c;

}

Answer : this(a,b)

24. write the code in Hex for 7

Answer : 0x07

25. Polygon is a Shape. This class has to access from any where is

the program..

Answer: public class Polygon extends Shape

26. String s = "Test"; Select all correct ans.

1. char c = "s";

2. s= s.append("For ")

3. s.length();

4. s.trim();

5. s = "For " + s;

Answer : 3,4 & 5

trim() returns the trimmed string so the output needs to be

assigned to another string as in :- s=s.trim();

27. In design the employee has the tasks in vector, Joining Date and

no. of depends. So following fields should be available in the class

of employee.

String

Vector

Date

Int

Float

Person

28. All the methods in Listener Interfaces should be

private

public

protected

undefined (friendly)

static

final

29. >> and >>> are

a.unsigned right shift and right rotate

b.unsigned right shift and signed right shift.

c.signed right shift and unsigned right shift.

d.Signed left shift and unsigned right shift.

e.signed left shift and unsigned left shift.

Answer : C

30 Best way to read the file as Strings.

Like

DataInputStream dis = new DataInputStream (new FileInputStream("test.txt"));

BufferedInputStream bis = new BufferInputStream (new FileInputStream("test"));

31.The parameter as to be passed for FilterInputStream.

File

String

Empty

FileReader

InputStream

32. Which of the following statements is true about the above code?

import java.awt.*;

import java.awt.event.*;

public class fram extends Frame

{

public static void main(String arg[])

{

fram f=new fram();

String msg="hello";

Button b=new Button("Click");

b.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

System.out.println(msg);

}

}

);

f.add(b);

f.pack();

f.show();

}

}

a.The code will not compile complaining that no layout has been

defined for the frame.

b.The code compiles and doesn't display anything.

c.The code runs and shows a single button occupying the whole frame.

On clicking the button you get the message "hello" at the Std o/p.

d.The code does not compile complaining about the inaccessibility of

a certain variable.

e.The code doesn't compile complaining that the constructor for fram

has not been defined.

Answer : D

the compilation error is

"Attempt to use a non-final variable msg from a different

method.From enclosing blocks, only final local variables are available.

System.out.println(msg);

^

"

 

33. Which of the following ?

1. public class sb

2.{

3. static public void main(String jk[])

{

StringBuffer s1=new StringBuffer("Hello");

StringBuffer s2=new StringBuffer("Hello");

meth(s1,s2);

System.out.println(s1+"\n"+s2);

}

private static void meth(StringBuffer s1,StringBuffer s2)

{

s2.append(" there");

s1=s2;

}

}

a.The code doesn't compile; it complains at line 3.

b.The code runs and produces O/p : Hello

Hello

c.The code runs and produces O/p : Hello

Hello there

d.The code runs and produces O/p : Hello there

Hello there

e.The code fails to compile saying the method meth is

declared private and is not accessible.

Answer : C

34. Which of the following?

class exSuper

{

public void func(String p,String s)

{

System.out.println(p);

}

}

public class example extends exSuper

{

public void func(String p,String s)

{

System.out.println(p+ " : " +s);

}

static public void main(String arg[])

{

exSuper e1=new exSuper();

e1.func("hello1","hi1");

exSuper e2=new example();

e2.func("hello2","hi2");

}

}

a.The code compiles and produces O/p : hello1 h1

hello2 hi2

b.The code compiles and produces O/p : hello1

hello2 hi2

c.The code compiles and produces O/p : hello1

hello2

d.The code compiles and produces O/p : hello1 h1

hello2

e.The code doesn't compile

Answer : B