Jump to content
ChetanaSforum
chetanaforum

(FAQ) 60 JAVA QUESTIONS

Recommended Posts

[ Contributed By : Kalpana Dhandapani ]

 

1. How do you create a Reader object from an inputstream object?

a. use the static createReader() method of the inputstream class.

b. use the static createReader() method of the reader class

c. create an inputstreamreader object, passing the inputstream object as an argument to the inputstreamreader constructor(*)

d. create an outputstreamreader object, passing the inputstream object as an argument to the outputstreamreader constructor.

 

2. which of the following are valid identifiers?

a. _id(*)

b. $id(*)

c. #id

d. -id

 

3. which of the following are true?

a. the sleep() method puts a thread in the ready state.

b. the yield() method puts a thread in the waiting state.

c. the suspend() method is the preferred method for stopping a thread's execution.

d. a thread's interrupt() method results in the throwing of the interruptedexception.(*)

 

4. which of the following classes have a paint() method?

a. canvas(*)

b. image

c. frame(*)

d. graphics

 

5. which statement creates textarea with 10 rows and 20 columns?

a. new TextArea(10,20)(*)

b. new TextArea(20,10)

c. new TextArea(Rows(10),Cols(20))

d. new TextArea(Row(10),Col(20))

 

6. which of the following are true?

a. the AWT automatically causes a window to be repainted when a portion of a window has been minimized and then maximized.(*)

b. the AWT automatically causes a window to be repainted when a portion of a window has been covered and then uncovered.(*)

c. the AWT automatically causes a window to be repainted when application data is changed.

d. the AWT does not support repainting operations.

 

 

7. which of the following are java keywords?

a. null

b. NULL

c. extends(*)

d. main

 

 

 

8. which of the following thread state transitions are valid?

a. from ready to running(*)

b. from running to ready(*)

c. from running to waiting(*)

d. from waiting to running

e. from waiting to ready(*)

f. from ready to waiting

 

 

9. which of the following is not a wrapper class?

a. string(*)

b. integer

c. boolean

d. character

 

 

10. which is the advantage of encapsulation?

a. only public methods are needed

b. no exceptions need to be thrown from any method

c. making the class final causes no cnsequential changes to other code.

d. it changes the implementation without changing the interface and causes no consequential changes to other code.(*)

e. it changes the interface without changing the implementatino and causes no consequential changes to other code.

 

 

11. which font attributes are available through the FontMetrics class?

a. ascent(*)

b. leading(*)

c. case

d. height(*)

 

 

12.which of the following are true?

a. component extends container

b. menuitem extends component

c. container extends component(*)

d. menucomponent extends component

 

 

13. what is the ovtal equivalent of the decimal value 123?

a. 0173(*)

b. 123

c. 0x123

d. 0x173

 

 

14. in order for the public class Myclass to successfully compile, which of the following are true?

a. myclasss must have a correctly formed main method

b. myclass must be defined in the file myclass.java(*)

c. myclass must be defined in the myclas package.

d. myclass must be imported

 

 

15. which of the following are true?

a. any unicode character is represented using 16 bits

b. seven bits are needed to represent any ASCII character

c. UTf-8 characters are represented using only eight bits.

d. UTF-16 characters are represented using only 16 bits.

 

 

16. which of the following are true about a dead thread?

a. the thread's object is discarded.

b. the thread must wait until all other threads execute before it is restarted

c. the thread cannot be restarted(*)

d. the thread is synchornized

 

 

17. what is the output displayed by the following program?

class question {

public static void main(String args[]) {

int n=7;

n<<=3;

n=n&n+1|n+2^n+3;

n>>=2;

System.out.println(n);

}

}

 

a. 0

b. -1

c. 14(*)

d. 64

 

 

18. which of the following are true?

a. a component may handle its own events by adding itself as an even listener(*)

b. a component may handle its own events by overriding its event-dispatching method.(*)

c. a component may not handle its own events

d. a component may handle its own events only if it implements the handleEvent() method

 

 

 

 

19. what can contain objects that have a unique key field of string type, if it is required to retrieve the objects using that key field as an inded?

a. map(*)

b. set

c. list

d. collection

e. enumeration

 

 

20. what output is displayed by the following program?

import java.io.*;

public class TestIOApp {

public static void main(String args[]) throws IOException{

StringReader stringin = new StringReader("test")

LineNumberReader in = new LineNumberReader(stringin);

PrintWriter out = new PrintWriter(System.out);

out.println(in.readLine());

out.flush();

}

}

a. test(*)

b. 1. test

c. 1: test

d. 1 test

 

 

 

21. which of the following are characteristic of a fully encapsulated class?

a. all variables are private(*)

b. all methods are private

c. methods are provided to access the class's properties(*)

d. the class's design may be changed with minimal impact on its implementation

 

 

22. which of the following are true about the finally clause of a try-catch-finally statement?

a. it is only executed after a catch clause has executed

b. it is only executed if a catch clause has not executed

c. it is always executed unless its thread terminates(*)

it is only executed if an exception is thrown

 

 

23. which layout stacks components on tope of each other?

a. cardlayout(*)

b. null layout

c. borderlayout

d. setlayout

 

 

 

24. which of the following components generate action events?

a. buttons(*)

b. labels

c. checkboxes

d. windows

 

 

25. which methods will cause a frame to be displayed?

a. show() (*)

b. setVisible() (*)

c. display()

d. displayFrame()

 

 

26. what is the range of the short type?

a. 0 to 2^16

b. -(2^16) to 2^16

c. -(2^15) to 2^15

d. -(2^15) to 2^15-1 (*)

 

 

 

27. what is the value of a[3] as the result of the following array declaration?

int[] a={1,2,3,4,5};

a.1

b.2

c.3

d.4(*)

 

 

 

28. whati s the output of the following program?

public class question {

public static void main(String args[]) {

boolean[] b = new boolean[2];

double[] d = new double[2];

System.out.print(b[0]);

System.out.println(d[1]);

a. true0.0

b. true0

c. false0.0 (*)

d. false0

 

 

 

29. what is the output of the following program?

class question {

static int i=1,j=2;

static {

display(i);

}

public static void main(String args[]) {

display(j);

static void display(int n) {

system.out.print(n);

}

}

a. 1

b. 2

c. 12(*)

d. 21

 

 

 

30. which of the following are true?

a. a top-level class may be declared as private

b. a method may be declared as transient

c. a constructor may be declared as volatile

d. a local variable may be declared as final(*)

 

 

 

 

31. when two or more objects are added as listners for the same event, which listener is first invoked to handle the event?

a. the first object that was added as a listener

b. the last object that was added as a listener

c. 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.

 

 

 

 

32. which of the following are true?

a. a reference to an array can be cast to a reference to an object(*)

b. a reference to an array can be cast to a reference to a cloneable(*)

c. a reference to an array can be cast to a reference to a string

d. none of the above

 

 

 

33. which layout is used to layout the components of a container in a grid where each row and column are the same size?

a. gridlayout

b. null layout

c. gridbaglayout

d. gridbagconstraintlayout

 

 

 

 

34. what is the output of the following program?

class outer {

string s = "outer";

public static void main(string args[]) {

new outer().new Inner();

}

outer() {

system.out.prints(s);

}

class inner {

string s = "inner";

inner() {

system.out.print(s);

}

}

}

a. outer

b. inner

c. outerinner(*)

d. innerouter

 

 

 

 

 

35. what is the result of the expression 5.4 + "3.2" ?

a. the double 8.6

b. the string 8.6

c. the long value 8

d. the string 5.43.2(*)

 

 

 

36. which are true about the container class?

a. the validate() method is used to cause a container to be laid out and redisplayed (*)

b. the add() method is used to add a component to a container (*)

c. the getborder() method returns information about a containers insets

d. the getcomponent() method is used to access a component that is contained in a container (*)

 

 

 

 

 

37. which of the following are true about this method declaration?

void mymethod(string s) { }

a. mymethod() is static

b. mymethod does not return a value(*)

c. mymethod is abstract

d. mymethod may not be accessed outside of a package in which it is declared(*)

 

 

 

 

 

38. which lines of output are displayed by the following program?

class question{

public static void main(string[] args) {

for(int i=0;i<10;i++) {

try {

try {

if (i%3==0) throw new Exception("E0");

system.out.println(i);

}

catch(exception inner) {

i *=2;

if(i%3==0) throw new exception("E1");

} finally {

++i;

}

}

catch(exception outer) {

i+=3;

} finally {

--i;

}

}

}

}

 

a. 4(*)

b. 5(*)

c. 6

d. 7

e. 8

f. 9

 

 

 

 

39. if you run the following program, what lines would be included in its output?

class question{

public static void main(string args[]) {

int i,j;

for(i=0,j=0;i+j<20;++i,j+=i--) {

system.out.println(i+j);

}

}

}

a. 5(*)

b. 8(*)

c. 13(*)

d. the program cannot be compiled because the for statement's syntax is incorrect.

 

 

 

 

40. which of the following are direct or indirect subclasses of component?

a. button(*)

b. label(*)

c. checkboxmenuitem

d. toolbar

e. frame(*)

 

 

 

 

41. which layout is the defauld layout of a panel object?

a. gridlayout

b. flowlayout(*)

c. gridlinelayout

d. linelayout

 

 

 

 

43. which of the following are true?

a. java only supports preemptive scheduling.

b. java only supports time slicing.

c. the jvm has been implemented on os that use time slicing(*)

d. the jvm has been implemented on os that use preemptive scheduling.(*)

 

 

 

 

 

44. what should you use to position a button within an application frame so that the size of the button is not affected by the frame size?

a. flowlayout(*)

b. gridlayout

c. the center area of a borderlayout

d. the east or west area of a borderlayout

e. the north or south area of a borderlayout

 

 

 

 

45. a catch clause may catch exceptions of which types?

a. thowable type(*)

b. error type(*)

c. exception(*)

d. string

 

 

 

46. what is the value displayed by the following program?

class question{

public static void main(string[] args) {

int x=0;

boolean b1,b2,b3,b4;

b1= b2= b3= b4= true;

x = (b1|b2&b3^b4)?x++:--x;

system.out.println(x)

}

}

 

a. 0(*)

b. -1

c. 1

d. none of the above

 

 

 

47. which method is used to set the text of a label object?

a. settext() (*)

b. setlabel()

c. settextlabel()

d. setlabeltext()

 

 

 

48. which of the following methods cause the string object referenced by s to be changed?

a. s.concat()

b. s.touppercase(0

c. s.replace()

d. none of the above(*)

 

 

49. in order for teh myprogram proram to be compiled and run, which of the followin must be true?

a. the myprogram class must be defined in myprogram.java

b. myprogram must be declared as public

c. myprogram must have correctly formed main() method(*)

d. myprogram must import java.lang

 

 

 

 

50. which of the followin are true?

a. textcomponent extends textarea

b. textarea extends textfield

c. textfield extends textcomponent(*)

d. textcomponent extends textfield

d. textarea extends textcomponent(*)

 

 

 

 

51. what is the value of 111%13?

a. 11

b. 5

c. 6

d. 7(*)

 

 

 

52. which of the following are methods of the graphics class?

a. drawrect() (*)

b. drawimage() (*)

c. drawpoint()

d. drawstring() (*)

 

 

 

53. if you run the following program, which lines would be included in its output?

class question {

public static void main(string[] args) {

int i=1;

int j=2;

outer: while(i<j) {

++i;

inner: do {

++j;

if (j%3==0) continue outer;

if (i%3==0) break inner;

if (i%3==1) break outer;

system.out.println(i*j);

} while (j < i);

system.out.println(i+j);

}

}

}

a. 5

b. 6

c. 7(*)

d. the program does not display any output.

 

 

 

54. what is the output of the following program?

class s1{

public static void main(string[] args) {

new s2();

}

s1() {

system.out.pritn("s1");

}

}

class s2 extends s1 {

s2() {

system.out.print("s2");

}

}

 

a. s1

b. s2

c. s1s2(*)

d. s2s1

 

 

 

55. what is the range of char type?

a. 0 to 2^16

b. 0 to 2^16-1(*)

c. 0 to 2^15

d. 0 to 2^15-1

 

 

 

 

56. which of the following methods are methods of math class?

a. absolute()

b. cosine()

c. sine()

d. log() (*)

 

 

 

57. which of the following are true about local inner classes?

a. they are not associated with any instance of an outer class.(*)

b. they may access final initialized variables and parameters that are in the scope of the statement block in which the class is declared(*)

c. they may be declared public, protected or private

d. they may not implement an interface

 

 

 

58. when a thread blocks on I/O, which of the following are true?

a. the thread enters the ready state.

b. the thread enters the dead state

c. no other thread may perform I/O

d. the thread enters the waiting state(*)

 

 

59. what is the output of the following program when it is invoked using the command line java Test this is a test?

class Test {

public static void main(String arg[]) {

system.out.println(arg[1]);

}

}

a. this

b. is(*)

c. a

d. test?

 

 

 

60. a frame's background color is set to color.yellow and button's background color is set to colr.blue. suppose the button is added to a panel, which is added to the frame. what background color will be used wth the panel?

a. color.yellow(*)

b. color.blue

c. color.green

d. color.white

Share this post


Link to post
Share on other sites

can i get the answer

You should first try them yourselve that way you will hone your java skill and when some totaly uncommon question is asked you will be able attempt solving them.

Share this post


Link to post
Share on other sites

Hi everybody, this is JohnRocks here.All the answer must be given in the last of the question paper. This thing allow the reader to discuss and apply skills on a particular question. In the last he can look the answer to ensure of himself or to match with correct answer. Thanks

Share this post


Link to post
Share on other sites

Thanks Admin...Good Collection of multiple choice Questions..

Share this post


Link to post
Share on other sites

I attended one interview the interviewer asked one question System.out.println("hellow world") ;we print "hellow world"Like that............can we write our own class and object and method ...........suppose assume class :Naidu object : gomethod : print12();Naidu.go.print12("hello world");i want to display hello worldplease answer me

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×