1.
Select Correct options in given below
A. 
Collection list = new ArrayList();
B. 
ArrayList list = new ArrayList();
C. 
ArrayList list = new ArrayList();
D. 
2.
3. public class Ouch {4. static int ouch = 7;5. public static void main(String[] args) {6. new Ouch().go(ouch);7. System.out.print(" " + ouch);8. }9. void go(int ouch) {10. ouch++;11. for(int ouch = 3; ouch < 6; ouch++)12. ;13. System.out.print(" " + ouch);14. }15. }
A. 
B. 
C. 
D. 
E. 
F. 
An exception is thrown at runtime
3.
Class Hexy { public static void main(String[] args) { Integer i = 42; String s = (i<40)?"life":(i>50)?"universe":"everything"; System.out.println(s); }}
A. 
B. 
C. 
D. 
E. 
F. 
. An exception is thrown at runtime
4.
Given:class Feline { public static void main(String[] args) { Long x = 42L; Long y = 44L; System.out.print(" " + 7 + 2 + " "); System.out.print(foo() + x + 5 + " "); System.out.println(x + y + foo()); } static String foo() { return "foo"; }}
A. 
B. 
C. 
D. 
E. 
F. 
5.
3. interface Vessel { }4. interface Toy { }5. class Boat implements Vessel { }6. class Speedboat extends Boat implements Toy { }7. public class Tree {8. public static void main(String[] args) {9. String s = "0";10. Boat b = new Boat();11. Boat b2 = new Speedboat();12. Speedboat s2 = new Speedboat();13. if((b instanceof Vessel) && (b2 instanceof Toy)) s += "1";14. if((s2 instanceof Vessel) && (s2 instanceof Toy)) s += "2";15. System.out.println(s);16. }17. }
A. 
B. 
C. 
D. 
6.
3. public class Theory {4. public static void main(String[] args) {5. String s1 = "abc";6. String s2 = s1;7. s1 += "d";8. System.out.println(s1 + " " + s2 + " " + (s1==s2));9.10. StringBuffer sb1 = new StringBuffer("abc");11. StringBuffer sb2 = sb1;12. sb1.append("d");13. System.out.println(sb1 + " " + sb2 + " " + (sb1==sb2));14. }15. }
A. 
B. 
The first line of output is abc abc true
C. 
The first line of output is abcd abc false
D. 
The second line of output is abcd abcd true
7.
Which statements are true about comparing two instances of the same class, given that theequals() and hashCode() methods have been properly overridden? (Choose all that apply.)
A. 
If the equals() method returns true, the hashCode() comparison == might return false
B. 
.If the equals() method returns false, the hashCode() comparison == might return true
C. 
If the hashCode() comparison== returns true, the equals() method must return true
D. 
.If the hashCode() comparison == returns true, the equals() method might return true
E. 
If the hashCode() comparison != returns true, the equals() method might return true
8.
Given:public static void before() {Set set = new TreeSet();set.add("2");set.add(3);set.add("1");Iterator it = set.iterator();while (it.hasNext())System.out.print(it.next() + " ");}
A. 
The before() method will print 12
B. 
The before() method will print 123
C. 
The before() method will throw an exception at runtime
D. 
The before() method will not compile
9.
Which collection class(es) allows you to grow or shrink its size and provides indexed access toits elements, but whose methods are not synchronized? (Choose all that apply.)
A. 
B. 
C. 
D. 
E. 
10.
Int Output = 10;
boolean b1 = false;
if((b1 == true) && ((Output += 10) == 20))
{
System.out.println("We are equal " + Output);
}
else
{
System.out.println("Not equal! " + Output);
}
A. 
Compilation error, attempting to perform binary comparison on logical data type.
B. 
Compilation and output of "We are equal 10".
C. 
Compilation and output of "Not equal! 20"
D. 
Compilation and output of "Not equal! 10".
11.
Public void foo( boolean a, boolean b)
{
if( a )
{
System.out.println("A"); /* Line 5 */
}
else if(a && b) /* Line 7 */
{
System.out.println( "A && B");
}
else /* Line 11 */
{
if ( !b )
{
System.out.println( "notB") ;
}
else
{
System.out.println( "ELSE" ) ;
}
}
}
A. 
If a is true and b is true then the output is "A && B"
B. 
If a is true and b is false then the output is "notB"
C. 
If a is false and b is true then the output is "ELSE"
D. 
If a is false and b is false then the output is "ELSE"
12.
Public void test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
A. 
B. 
"odd" will always be output.
C. 
"even" will always be output.
D. 
"odd" will be output for odd values of x, and "even" for even values.
13.
In the following pieces of code, A and D will compile without any error. True or false?A: StringBuffer sb1 = "abcd";B: Boolean b = new Boolean("abcd");C: byte b = 255;D: int x = 0x1234;E: float fl = 1.2;
14.
What is the result when you compile and run the following code?public class Test
{
public void method()
{
for(int i = 0; i < 3; i++)
{
System.out.print(i);
}
System.out.print(i);
}
}
A. 
B. 
C. 
D. 
15.
What is displayed when the following code is compiled and executed?String s1 = new String("Test");
String s2 = new String("Test");
if (s1==s2)
System.out.println("Same");
if (s1.equals(s2))
System.out.println("Equals");
A. 
B. 
C. 
D. 
The code compiles, but nothing is displayed upon execution.
16.
Class PassS
{
public static void main(String [] args)
{
PassS p = new PassS();
p.start();
}
void start()
{
String s1 = "slip";
String s2 = fix(s1);
System.out.println(s1 + " " + s2);
}
String fix(String s1)
{
s1 = s1 + "stream";
System.out.print(s1 + " ");
return "stream";
}
}
A. 
B. 
C. 
D. 
17.
Class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
A. 
B. 
C. 
D. 
18.
Class Test
{
public static void main(String [] args)
{
int x= 0;
int y= 0;
for (int z = 0; z < 5; z++)
{
if (( ++x > 2 ) || (++y > 2))
{
x++;
}
}
System.out.println(x + " " + y);
}
}
A. 
B. 
C. 
D. 
19.
Class Test
{
static int s;
public static void main(String [] args)
{
Test p = new Test();
p.start();
System.out.println(s);
}
void start()
{
int x = 7;
twice(x);
System.out.print(x + " ");
}
void twice(int x)
{
x = x*2;
s = x;
}
}
A. 
B. 
C. 
D. 
20.
Int [] a = {1,2,6,"7"};System.out.println(a[3]);
A. 
B. 
C. 
D.