Java Programming - Java.lang Class
Exercise : Java.lang Class - Finding the output
- Java.lang Class - General Questions
- Java.lang Class - Finding the output
- Java.lang Class - Pointing out the correct statements
26.
What will be the output of the program?
public class Test
{
public static void main(String[] args)
{
final StringBuffer a = new StringBuffer();
final StringBuffer b = new StringBuffer();
new Thread()
{
public void run()
{
System.out.print(a.append("A"));
synchronized(b)
{
System.out.print(b.append("B"));
}
}
}.start();
new Thread()
{
public void run()
{
System.out.print(b.append("C"));
synchronized(a)
{
System.out.print(a.append("D"));
}
}
}.start();
}
}
Answer: Option
Explanation:
It gives different output while executing the same compiled code at different times.
C:\>javac Test.java C:\>java Test ABBCAD C:\>java Test ACADCB C:\>java Test ACBCBAD C:\>java Test ABBCAD C:\>java Test ACBCBAD C:\>java Test ACBCBAD C:\>java Test ABBCAD
27.
What will be the output of the program?
String s = "hello";
Object o = s;
if( o.equals(s) )
{
System.out.println("A");
}
else
{
System.out.println("B");
}
if( s.equals(o) )
{
System.out.println("C");
}
else
{
System.out.println("D");
}
- A
- B
- C
- D
28.
What will be the output of the program (in jdk1.6 or above)?
public class BoolTest
{
public static void main(String [] args)
{
Boolean b1 = new Boolean("false");
boolean b2;
b2 = b1.booleanValue();
if (!b2)
{
b2 = true;
System.out.print("x ");
}
if (b1 & b2) /* Line 13 */
{
System.out.print("y ");
}
System.out.println("z");
}
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers