Home - Java Programming - Language Fundamentals

Language Fundamentals Online Exam Quiz

Important questions about Language Fundamentals. Language Fundamentals MCQ questions with answers. Language Fundamentals exam questions and answers for students and interviews.

1. Which four options describe the correct default values for array elements of the types indicated? int -> 0 String -> "null" Dog -> null char -> '\u0000' float -> 0.0f boolean -> true

Options

A : 1, 2, 3, 4

B : 1, 3, 4, 5

C : 2, 4, 5, 6

D : 3, 4, 5, 6

2. Which one of these lists contains only Java programming language keywords?

Options

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

3. Which three are legal array declarations? int [] myScores []; char [] myChars; int [6] myScores; Dog myDogs []; Dog myDogs [7];

Options

A : 1, 2, 4

B : 2, 4, 5

C : 2, 3, 4

D : All are correct.

4. Which will legally declare, construct, and initialize an array?

Options

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};

5. What will be the output of the program? 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.print(" " + argCopy[0][y]); } } } and the command-line invocation is > java CommandArgsThree 1 2 3

Options

A : 0 0

B : 1 2

C : 0 0 0

D : 1 2 3

6. What will be the output of the program? public class X { 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

Options

A : names

B : null

C : Compilation fails

D : An exception is thrown at runtime

7. What will be the output of the program, if this code is executed with the command line: > java F0091 world public class F0091 { public void main( String[] args ) { System.out.println( "Hello" + args[0] ); } }

Options

A : Hello

B : Hello Foo91

C : Hello world

D : The code does not run.

8. What will be the output of the program? public class CommandArgsTwo { public static void main(String [] argh) { int x; x = argh.length; for (int y = 1; y <= x; y++) { System.out.print(" " + argh[y]); } } } and the command-line invocation is > java CommandArgsTwo 1 2 3

Options

A : 0 1 2

B : 1 2 3

C : 0 0 0

D : An exception is thrown at runtime

9. What will be the output of the program? public class TestDogs { public static void main(String [] args) { Dog [][] theDogs = new Dog[3][]; System.out.println(theDogs[2][0].toString()); } } class Dog { }

Options

A : null

B : theDogs

C : Compilation fails

D : An exception is thrown at runtime

10. What will be the output of the program? 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 + ", "); } }

Options

A : 10, 9, 8, 7, 6,

B : 9, 8, 7, 6, 5,

C : Compilation fails.

D : An exception is thrown at runtime.

1. What will be the output of the program? 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 is > java CommandArgs 1 2 3 4

Options

A : args[2] = 2

B : args[2] = 3

C : args[2] = null

D : An exception is thrown at runtime.

2. In the given program, how many lines of output will be produced? 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); } } } }

Options

A : 7

B : 9

C : 11

D : 13

1. Which three piece of codes are equivalent to line 3? final int k = 4; public int k = 4; static int k = 4; abstract int k = 4; volatile int k = 4; protected int k = 4; public interface Foo { int k = 4; /* Line 3 */ }

Options

A : 1, 2 and 3

B : 2, 3 and 4

C : 3, 4 and 5

D : 4, 5 and 6

2. Which is the valid declarations within an interface definition?

Options

A : public double methoda();

B : public final double methoda();

C : static void methoda(double d1);

D : protected void methoda(double d1);

3. Which one is a valid declaration of a boolean?

Options

A : boolean b1 = 0;

B : boolean b2 = 'false';

C : boolean b3 = false;

D : boolean b4 = Boolean.false();

4. What is the numerical range of a char?

Options

A : -128 to 127

B : -(2 15) to (2 15 ) - 1

C : 0 to 32767

D : 0 to 65535

5. Which is a valid declarations of a String?

Options

A : String s1 = null;

B : String s2 = 'null';

C : String s3 = (String) 'abc';

D : String s4 = (String) '\ufeed';

6. Which is a valid keyword in java?

Options

A : interface

B : string

C : Float

D : unsigned

7. Which one of the following will declare an array and initialize it with five numbers?

Options

A : Array a = new Array(5);

B : int [] a = {23,22,21,20,19};

C : int a [] = new int[5];

D : int [5] array;

8. Which three are valid declarations of a float? float f1 = -343; float f2 = 3.14; float f3 = 0x12345; float f4 = 42e7; float f5 = 2001.0D; float f6 = 2.81F;

Options

A : 1, 2, 4

B : 2, 3, 5

C : 1, 3, 6

D : 2, 4, 6

Java Programming more Online Exam Quiz

Copyright © 2021
Exam-GK-MCQ-Questions.Com | Contact Us | Privacy Policy | Terms of Use | Sitemap | 0.017979860305786