Java Programming Fundamentals

Covers Java basics including arrays, loops, constructors, inheritance, and method overloading

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What is the output of the given program?

public class ScopeTest
{
public static void main (String [] args)
{
int[][] xx[][][] = null;
System.out.println(xx);
}
}

  1. Compilation Fails
  2. Null
  3. 0
  4. Java.lang.ArrayIndexOutOfBoundException
  5. Java.lang.NullPointerException
Question 2 Multiple Choice (Single Answer)

Which of the following packages are automatically imported into the java source file by the java compiler?

Public Class Test
{
}

  1. Java.lang
  2. Java.awt
  3. The package with no name
  4. Java.*
  5. Both (1) and (3)
Question 3 Multiple Choice (Single Answer)

What is the output of the given program?

public class ScopeTest
{
public static void main (String [] args)
{
int ii = 2;
do
{
System.out.println (ii);
}
while (--ii);
}
}

  1. 1
  2. 2
  3. Null
  4. Infinite loop
  5. Compilation Error
Question 4 Multiple Choice (Single Answer)

Which of the following is the output of the given program?

public static void main(Stirng[] args)
{
int x = 353;
int j = x++;
switch (j)
{
case 317: case 353: case 367: System.out.println(Is a prime number.);
case 353: case 363: System.out.println(Is a palindrome.);
break;
default: System.out.println(Invalid value.);
}
}

  1. It is a prime number.
  2. It is a palindrome.
  3. It is a prime number. It is a palindrome.
  4. Invalid value
  5. Compilation fails
Question 5 Multiple Choice (Single Answer)

What is the output of the given program code?

public class ScopeTest
{
int z;
public static void main(String[] args)
{
ScopeTest myScope = new ScopeTest();
int z = 6;
System.out.println(myScope.z);
System.out.println(z);
myScope.doStuff();
System.out.println(z);
System.out.println(myScope.z);
}
void doStuff()
{
int z = 5;
doStuff2();
System.out.println(z);
}
void doStuff2()
{
z = 4;
}
}

  1. Garbage value 6 5 6 4
  2. 6 6 5 6 4
  3. 0 6 5 6 4
  4. Compilation error
  5. Run time error
Question 6 Multiple Choice (Single Answer)

What is the output of the given program?

public class ScopeTest
{
public static void main (String [] args)
{
int[][] xx[][][] = null;
if(xx)
{
System.out.println(xx);
}
else
{
System.out.println("False");
}
}
}

  1. Null
  2. False
  3. Java.Lang.NullPointerException
  4. 0
  5. Compilation fails
Question 7 Multiple Choice (Single Answer)

Which of the given classes has default constructor?
Class X { }

Class Y { Y() {} }

Class Z { Z(int i) { } }

  1. X Only
  2. Y Only
  3. Z Only
  4. X and Z
  5. X and Y
Question 8 Multiple Choice (Single Answer)

Which of the following are valid declarations for two dimensional array?

  1. Int[][] Array;
  2. Int[] Array[];
  3. Int[2][2] Array;
  4. Both (1) and (2)
  5. All of these
Question 9 Multiple Choice (Single Answer)

What is the output of the given program code?

public class ScopeTest
{
public static void main(String[] args)
{
int [] xx = null;
for(int i=0;i

  1. Null
  2. Java.lang.NullPointerException
  3. 0
  4. Compilation fails
  5. None of these
Question 10 Multiple Choice (Single Answer)

How many times is “aa” printed as a part of output?

public class ScopeTest
{
int z;
public static void main(String[] args)
{
String[] table = {"aa", "bb", "cc"};
for (String ss: table)
{
int ii = 0;
while (ii < table.length)
{
System.out.println(ss + ", " + ii);
ii++;
}
}
}
}

  1. Zero times
  2. Once
  3. Twice
  4. Thrice
  5. Compilation fails
Question 11 Multiple Choice (Single Answer)

What is the output of the given program?

class ScopeTest
{
int x(double d)
{
System.out.println("one");
return 0;
}
String x(double d)
{
System.out.println("two");
return null;
}
double x(double d)
{
System.out.println("three");
return 0.0;
}
public static void main(String[] args)
{
new Overloading().x(4.0);
}
}

  1. One
  2. Two
  3. Three
  4. Compilation fails
  5. Run time error
Question 12 Multiple Choice (Single Answer)

What is the output of the given program code?

public class ScopeTest
{
public static void main(String[] args)
{
ScopeTest sc, scA, scB;
sc = new ScopeTest();
scA = new ScopeTestA();
scB = new ScopeTestB();
System.out.println("Hash is : " + sc.getHash() + ", " + scA.getHash() + ", " + scB.getHash());
}
public int getHash()
{
return 111111;
}
}
class ScopeTestA extends ScopeTest
{
public long getHash()
{
return 44444444;
}
}
class ScopeTestB extends ScopeTest
{
public long getHash()
{
return 999999999;
}
}

  1. Hash is: 111111, 44444444, 999999999
  2. Blank output screen
  3. An exception is thrown at runtime
  4. Compilation Fails
  5. None of these
Question 13 Multiple Choice (Single Answer)

What is the output of the given program?

Int [] [] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}};
Systemout.printIn(array [2] [1]);
System.out.printIn (array) [2][4]);

  1. 1 null
  2. Null null
  3. 2 an ArrayIndexOutofbound Exception is thrown
  4. ArrayIndexOutofbound Exception is thrown
  5. Compilation fails
Question 14 Multiple Choice (Single Answer)

What is the output of the given program?

class A
{
int a;
A(int a)
{
System.out.println(a);
}
public void display()
{
System.out.println("Hello");
}
}
class ScopeTest extends A
{
public static void main(String[] args)
{
ScopeTest s1 = new ScopeTest();
s1.display();
}
}

  1. Hello
  2. 0
  3. Run time error
  4. Compilation error
  5. Blank output screen
Question 15 Multiple Choice (Single Answer)

How many times is 1 printed as a part of output?

public class ScopeTest
{
int z;
public static void main(String[] args)
{
String[] table = {"aa", "bb", "cc"};
for (String ss: table)
{
int ii = 0;
while (ii < table.length)
{
System.out.println(ss + ", " + ii); ii++;
}
}
}
}

  1. Zero times
  2. Once
  3. Twice
  4. Thrice
  5. Compilation fails