What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() {}
}
Answer
What will be the output of the program?
public class RTExcept
{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
System.out.println("after ");
}
}
Answer
What will be the output of the program?
public class Test
{
public static void main(String [] args)
{
int I = 1;
do while ( I < 1 )
System.out.print("I is " + I);
while ( I > 1 ) ;
}
}
Answer
Which two statements are equivalent?
Which of the following are legal lines of code?
What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
Answer
Which three statements are true?
which two code fragments inserted at end of the program, will allow to compile?
interface DoMath
{
double getArea(int rad);
}
interface MathPlus
{
double getVol(int b, int h);
}
/* Missing Statements ? */
Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class?
AnswerWhat will be the output of the program?
public class BoolTest
{
public static void main(String [] args)
{
int result = 0;
Boolean b1 = new Boolean("TRUE");
Boolean b2 = new Boolean("true");
Boolean b3 = new Boolean("tRuE");
Boolean b4 = new Boolean("false");
if (b1 == b2) /* Line 10 */
result = 1;
if (b1.equals(b2) ) /* Line 12 */
result = result + 10;
if (b2 == b4) /* Line 14 */
result = result + 100;
if (b2.equals(b4) ) /* Line 16 */
result = result + 1000;
if (b2.equals(b3) ) /* Line 18 */
result = result + 10000;
System.out.println("result = " + result);
}
}
Answer
What will be the output of the program?
public class Test
{
public static void main(String[] args)
{
int x = 0;
assert (x > 0) ? "assertion failed" : "assertion passed" ;
System.out.println("finished");
}
}
Answer
Which will contain the body of the thread?
AnswerWhich three guarantee that a thread will leave the running state?
which statement, inserted at line 10, creates an instance of Bar?
class Foo
{
class Bar{ }
}
class Test
{
public static void main (String [] args)
{
Foo f = new Foo();
/* Line 10: Missing statement ? */
}
}
Answer
What will be the output of the program?
TreeSet map = new TreeSet();
map.add("one");
map.add("two");
map.add("three");
map.add("four");
map.add("one");
Iterator it = map.iterator();
while (it.hasNext() )
{
System.out.print( it.next() + " " );
}
Answer
What will be the output of the program?
import java.util.*;
class H
{
public static void main (String[] args)
{
Object x = new Vector().elements();
System.out.print((x instanceof Enumeration)+",");
System.out.print((x instanceof Iterator)+",");
System.out.print(x instanceof ListIterator);
}
}
Answer
Which is valid declaration of a float?
AnswerWhich statement is true?
Answerand given that all methods of class FileOutputStream, including close(), throw an IOException, which of these is true?
import java.io.*;
public class MyProgram
{
public static void main(String args[])
{
FileOutputStream out = null;
try
{
out = new FileOutputStream("test.txt");
out.write(122);
}
catch(IOException io)
{
System.out.println("IO Error.");
}
finally
{
out.close();
}
}
}
Answer
What will be the output of the program?
public class Test
{
public static void main(String args[])
{
int i = 1, j = 0;
switch(i)
{
case 2: j += 6;
case 4: j += 1;
default: j += 2;
case 0: j += 4;
}
System.out.println("j = " + j);
}
}
Answer
© 2017 QuizBucket.org