Java
Description: Java, programming | |
Number of Questions: 15 | |
Created by: Niharika Sharma | |
Tags: Java Concept Base Questions Java Basics |
What is the output of the given program?
public class ScopeTest
{
public static void main (String [] args)
{
int[][] xx[][][] = null;
System.out.println(xx);
}
}
Which of the following packages are automatically imported into the java source file by the java compiler?
Public Class Test
{
}
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);
}
}
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.);
}
}
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;
}
}
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");
}
}
}
Which of the given classes has default constructor? Class X { }
Class Y { Y() {} }
Class Z { Z(int i) { } }
Which of the following are valid declarations for two dimensional array?
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
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++;
}
}
}
}
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);
}
}
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;
}
}
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]);
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();
}
}
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++;
}
}
}
}