top of page
Search

JAVA - Multiple Choice Questions (Set I)

public class Test {

public static void main(String []args) {

signed int x = 10;

for (int y=0;y<5;y++, x++)

System.out.print(" " + x);

}

}

What is the result? (choose one)

A. 10 9 8 7 6 B. 9 8 7 6 5

C. Compilation fails D. An exception is thrown at run time.

Click here for Answer.

A. method B. native C. subclasses D. reference E. array

Click here for Answer.

A. class, if, void, long, int , continue

B. goto, instanceof, native, finally, default, throws

C. try, virtual, throw, final, volatile, transient

D. strictfp, constant, super, implements, do

E. byte, break, assert, switch, include

Click here for Answer.

A. interface B. unsigned C. Float D. this E. string

Click here for Answer.

A. char c1 = 064770; B. char c2 = 'face';

C. char c3 = 0xbeef ; D. char c4 = \u0022;

E. char c5 = '\iface'; F. char c6 = '\uface'

Click here for Answer.

A. String s1 = null; B. String s2 = "null'; C. String s3 = (String) 'abc';

D. String s4 = (String) '\ufeed'; E. String s5 = "strings rule"

Click here for Answer.

A. boolean b1 = 0; B. boolean b2 = 'false' C. boolean b3 = false

D. boolean b4 = Boolean.false(); E. boolean b5 = no;

Click here for Answer.

A. -128 to 127 B. -(2^15) to (2^15)-1 C. 0 to 32767

D. Platform dependent E. 0 to 65535

Click here for Answer.

A. float f1 = -343 B. float f2 = 3.14 C. float f3 = 0x12345 D. float f4 = 42e7

E. float f5 = 2001.0D; F. float f6 = 2.81F;

Click here for Answer.

A. int []myScores []; B. char []myChars; C. int [6] myScores;

D. Dpg MyDogs []; E. Dog MyDogs [7];

Click here for Answer.

public class Test {

public static void main(String[] args) {

int [] [] [] x = new int [3] [] [];

int i,j;

x[0] = new int[4][];

x[1] = new int[2][];

x[2] = new int[5][];

for (i=0;i<x.length;i++)

for(j=0;j<x[i].length;j++)

{

x[i][j] = new int[i+j+1];

System.out.println("size = " + x[i][j].length);

}

}

}

hoe many lines of output will be produced? (Choose one)

A. 7 B. 9 C. 11 D. 13

E. Compilation Fails F. An exception is thrown runtime.

Click here for Answer.

public class Test {

public static void main(String[] args) {

byte [] [] big = new byte[7][7];

byte [] [] b = new byte[2][1];

byte b3 = 5;

byte b2 [] [] [] []= new byte [2][3][1][2];

// insert code here

}

}

Which of the following lines of code could be inserted , and still allow the code to compile?(Choose four)

A. b2[0][1] = b; B. b[0][0] = b3; C. b2[1][1][0] = b[0][0]; D.b2[1][2][0] = b;

E. b2[0][1][0][0] = b[0][0]; F. b2[0][1] = big;

Click here for Answer.

A. Array a = new Array(5); B. int []a = {23,22,21,20,19} C. int []array;

D. int array[] = new int[5]; E. int a[] = new int(5); F. int [5] array;

Click here for Answer.

A. int []myList = {"1" , "2" , "3" }; B. int [] myList = ( 5, 8, 2 );

C. int myList [] [] = { 4, 9, 7, 0 } D. int myList[] = { 4, 3, 7 };

E. int []myList = [3, 6, 6]; F. int myList [] = { 4; 6; 5};

Click here for Answer.

A. int -> 0 B. String -> "null" C. Dog -> null

D. char -> '\u0000' E. float -> 0.0f F. boolean -> true

Click here for Answer.

public class TestDogs {

public static void main(String[] args) {

Dog [][] theDogs = new Dog[3][];

System.out.println(theDogs[2][0].toString());

}

}

class Dog { }

What is the result?(Choose two)

A. null B. theDogs

C. Compilation Fails D. An exception is thrown at runtime

Click here for Answer.

public class Main

{

public static void main(String[] args) {

String names[] = new String[5];

for(int x=0; x < args.length; x++)

names[x] = args[x];

System.out.println(names[2]);

}

}

and the command line invocation is

>java X a b

What is the result?

A. names B. null

C. Compilation Fails D. An Exception is thrown at runtime

Click here for Answer.

public class CommandArgs

{

public static void main(String[] args) {

String s1 = args[1];

String s2 = args[2];

String s3 = args[3];

String s4 = args[4];

System.out.print(" args[2] = " + s2);

}

}

and the command line invocation,

>java CommandArgs 1 2 3 4

What is the result?

A. args[2] = 2 B. args[2] = 3 C. args[2] = null D. args[2] = 1

E. Compilation Fails F. An exception is thrown at runtime

Click here for Answer.

public class CommandArgsTwo

{

public static void main(String[] argh) {

String []args;

int x;

x=argh.length;

for(int y = 1 ; y <= x; y++) {

System.out.println(" " + argh[y]);

}

}

}

and the command line invocation,

>java CommandArgsTwo 1 2 3

what is the result?

A. 0 1 2 B. 1 2 3 C. 0 0 0 D. null null null

E. Compilation Fails F. An exception is thrown at runtime

Click here for Answer.

public class CommandArgsThree

{

public static void main(String[] args) {

String [][] argCopy = new String[2][2];

int x;

argCopy[0] = args;

x = argCopy[0].length;

for(int y=0; y < x ; y++) {

System.out.println(" " + argCopy[0][y]);

}

}

}

and the command-line invocation,

>java CommandArgsThree 1 2 3

What is the result?

A. 0 0 B. 1 2 C. 0 0 0 D. 1 2 3

E. Compilation Fails F. An Exception is thrown at runtime

Click here for Answer.

    Want to read more?

    Subscribe to questionbankos.com to keep reading this exclusive post.

     
     
     

    Recent Posts

    See All
    Upcoming Sessions

    We are organizing sessions on various topics for members of our website. Some sessions will be absolutely free for all members which will be updated in due course. For more information , WhatsApp on 9

     
     
     
    Mastering Data Structures & Algorithms

    Recommended only for Advanced Learners having sound knowledge of Programming in C/C++/Java/Python. Duration - 3 Months (80 sessions approx) Fees - INR 12,000/- Session Time - Evening (9:00 PM - 10:00

     
     
     
    bottom of page