Java Language Fundamentals Mcqs

Our collections of Multiple choice questions and answers focuses on study of Java Language Fundamentals. These questions are chosen from a collection of most authoritative and best reference books on Java. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various tests and job interviews. One should practice our Mcqs to assimilate Java Language Fundamentals topic comprehensively.

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

Class, if, void, long, Int, continue

Goto, instanceof, native, finally, default, throws

Try, virtual, throw, final, volatile, transient

Strictfp, constant, super, implements, do

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

Int [] myList = {"1", "2", "3"};

Int [] myList = (5, 8, 2);

Int myList [] [] = {4,9,7,0};

Int myList [] = {4, 3, 7};

5.
Which three are valid declarations of a float?

1. float f1 = -343;
2. float f2 = 3.14;
3. float f3 = 0x12345;
4. float f4 = 42e7;
5. float f5 = 2001.0D;
6. float f6 = 2.81F;

1, 2, 4

2, 3, 5

1, 3, 6

2, 4, 6

7.
Which three are legal array declarations?

1. int [] myScores [];
2. char [] myChars;
3. int [6] myScores;
4. Dog myDogs [];
5. Dog myDogs [7];

1, 2, 4

2, 4, 5

2, 3, 4

All are correct.

8.
Which three piece of codes are equivalent to line 3?

1. final int k = 4;
2. public int k = 4;
3. static int k = 4;
4. abstract int k = 4;
5. volatile int k = 4;
6. protected int k = 4;


public interface Foo 
{ 
    int k = 4; /* Line 3 */
}

1, 2 and 3

2, 3 and 4

3, 4 and 5

4, 5 and 6

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

Array a = new Array(5);

Int [] a = {23,22,21,20,19};

Int a [] = new int[5];

Int [5] array;

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

Public double methoda();

Public final double methoda();

Static void methoda(double d1);

Protected void methoda(double d1);

11.
What will be the output of the program?

Note: The command-line invocation > java CommandArgsThree 1 2 3


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

0 0

1 2

0 0 0

1 2 3

12.
What will be the output of the progra Note: The command-line invocation is

> java CommandArgs 1 2 3 4


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

Args[2] = 2

Args[2] = 3

Args[2] = null

An exception is thrown at runtime.

13.
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] ); 
    } 
}

Hello

Hello Foo91

Hello world

The code does not run.

14.
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 { }

Null

TheDogs

Compilation fails

An exception is thrown at runtime

15.
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 + ", ");
    }
}

10, 9, 8, 7, 6,

9, 8, 7, 6, 5,

Compilation fails.

An exception is thrown at runtime.

0Shares
0
Scroll to Top