Core Java (GATE - CS)
Description: Core Java | |
Number of Questions: 15 | |
Created by: Niharika Sharma | |
Tags: Core Java Java Basics |
What changes will make the above code compile?
class X { X () { } private void one () { }
}
public class Y extends X { Y () { } private void two () { one();
}
public static void main (String [] args) { new Y().two ();
}
}
What is the output of the given program?
int [] array = {1, 2, 3, 4, 5};
System.arraycopy (array, 2, array, 1, 2);
System.out.print (array [1]);
System.out.print (array[4]);
What is the output of the given program?
StringBuilder sb = new StringBuilder ();
String h1 = HelloWorld;
sb.append(Hello).append (world);
if (h1 == sb.toString())
{
System.out.println(They match);
}
if (h1.equals(sb.toString()))
{
System.out.println(They really match);
}
What is the output of the given code?
String message1 = Wham bam!;
String message2 = new String(Wham bam!);
if (message1 == message2)
System.out.println(They match);
if (message1.equals(message2))
System.out.println(They really match);
What is the output of the given code?
public class MyFor3
{
public static void main(String[] args)
{
int [] xx = null; System.out.println(xx);
}
}
What is the output of the given program code?
public class ScopeTest
{
int z;
public static void main(String[] args)
{
String theString = "Hello World";
System.out.println(theString.charAt(11));
}
}
How many times is 2 printed as 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?
public class ScopeTest
{
public static void main (String [] args)
{
int [] array = {1, 2, 3, 4, 5};
System.arraycopy (array, 2, array, 2);
System.out.print (array [1]);
System.out.print (array[4]);
}
}
What is the output of the given program code?
public class ScopeTest
{
public static void main (String [] args)
{
String[] table = {aa, bb, cc};
int ii =0;
do while (ii < table.length);
System.out.println(ii++);
while (ii < table.length);
}
}
What is the output of the given Java program?
public class MyClass
{
public static void main(String[] args)
{
String s = " Java Duke ";
int len = s.trim().length();
System.out.print(len);
}
}
Which of the following options are correct? interface Pet { } class Dog implements Pet { } public class Beagle extends Dog{ }
What is the output of the given program?
public class arr
{
public static void main(String[] args)
{
int array[] = {0, 1, 2, 3, 4};
int key = 3;
for (int pos = 0;
pos < array.length; ++pos)
{
if (array[pos] == key)
{
break;
}
}
System.out.print("Found " + key + "at " + pos);
}
}
How many times is 0 printed as 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 code?
Int [] [] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}};
Systemout.printIn(array [4] [1]);
System.out.printIn (array) [1][4]);
What is the output of the given program?
public class ScopeTest
{
int z;
public static void main(String[] args)
{
ScopeTest myScope = new ScopeTest();
int z = 6;
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;
}
}