Core Java Basic Assesment-1 Solution
Core Java Basic Assesment-1 Solution
types indicated?
1. int -> 0
2. String -> "null"
3. Dog -> null
4. char -> '\u0000'
5. float -> 0.0f
6. boolean -> true
1,2,3,4
1,3,4,5
2,4,5,6
3,4,5,6
Correct Answer: - B
1,3,4,5
Q2:- Which one of these lists contains only Java programming language keywords?
class, if, void, long, Int, continue
Q4:-
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" ) ;
}
}
}
Q5:-
public void test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
Compilation Fails
"odd" will be output for odd values of x, and "even" for even values.
Correct Answer: - A
Compilation Fails
Q6:-
public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}
Which statement is true?
Q7:-
class PassA
{
public static void main(String [] args)
{
PassA p = new PassA();
p.start();
}
void start()
{
long [] a1 = {3,4,5};
long [] a2 = fix(a1);
System.out.print(a1[0] + a1[1] + a1[2] + " ");
System.out.println(a2[0] + a2[1] + a2[2]);
}
12 15
15 15
345375
375375
Correct Answer: - B
15 15
Q8:-
class Test
{
public static void main(String [] args)
{
Test p = new Test();
p.start();
}
void start()
{
boolean b1 = false;
boolean b2 = fix(b1);
System.out.println(b1 + " " + b2);
}
false true
true false
false false
Correct Answer: - B
false true
Q9:-
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);
}
slipstream
slip stream
slipstream slip
Q10:-
class Equals
{
public static void main(String [] args)
{
int x = 100;
double y = 100.1;
boolean b = (x = y); /* Line 7 */
System.out.println(b);
}
}
What will be the output of the program?
TRUE
FALSE
Compilation Fails
Exception at Runtime
Correct Answer: - C
Compilation Fails
Q11:-
class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
What will be the output of the program?
small
tiny
huge
Compilation Fails
Correct Answer: - B
tiny
Q12:-
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);
}
}
52
53
63
64
Correct Answer: - C
63
Q13:-
class Bitwise
{
public static void main(String [] args)
{
int x = 11 & 9;
int y = x ^ 3;
System.out.println( y | 12 );
}
}
14
Correct Answer: - D
14
Q14:-
class SSBool
{
public static void main(String [] args)
{
boolean b1 = true;
boolean b2 = false;
boolean b3 = true;
if ( b1 & b2 | b2 & b3 | b2 ) /* Line 8 */
System.out.print("ok ");
if ( b1 & b2 | b2 & b3 | b2 | b1 ) /*Line 10*/
System.out.println("dokey");
}
}
ok
dokey
ok dokey
Compilation Fails
Correct Answer: - B
dokey
1 and 2
2 and 3
3 and 4
Q16:-
class CompareReference
{
public static void main(String [] args)
{
float f = 42.0f;
float [] f1 = new float[2];
float [] f2 = new float[2];
float [] f3 = f1;
long x = 42;
f1[0] = 42.0f;
}
}
import java.awt.Button;
class CompareReference
{
public static void main(String [] args)
{
float f = 42.0f;
float [] f1 = new float[2];
float [] f2 = new float[2];
float [] f3 = f1;
long x = 42;
f1[0] = 42.0f;
}
}
which three statements are true?
1. f1 == f2
2. f1 == f3
3. f2 == f1[1]
4. x == f1[0]
5. f == f1[0]
1,2 and 3
2, 4 and 5
3, 4 and 5
1, 4 and 5
Correct Answer: - B
2, 4 and 5
1, 3 and 4
2, 4 and 5
1, 2 and 6
2, 5 and 6
Correct Answer: - C
1, 2 and 6
Q19:-
class SC2
{
public static void main(String [] args)
{
SC2 s = new SC2();
s.start();
}
void start()
{
int a = 3;
int b = 4;
System.out.print(" " + 7 + 2 + " ");
System.out.print(a + b);
System.out.print(" " + a + b + " ");
System.out.print(foo() + a + b + " ");
System.out.println(a + b + foo());
}
String foo()
{
return "foo";
}
}
9 7 7 foo 7 7foo
72 34 34 foo34 34foo
9 7 7 foo34 34foo
72 7 34 foo34 7foo
Correct Answer: - D
72 7 34 foo34 7foo
Q20:-
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;
}
}
77
7 14
14 0
14 14
Correct Answer: - B
7 14
Q21:-
class BoolArray
{
boolean [] b = new boolean[3];
int count = 0;
void test()
{
if ( b[0] && b[1] | b[2] )
count++;
if ( b[1] && b[(++count - 2)] )
count += 7;
System.out.println("count = " + count);
}
}
count = 0
count = 2
count = 3
count = 4
Correct Answer: - C
count = 3
Q22:-
public class Test
{
public static void leftshift(int i, int j)
{
i <<= j;
}
public static void main(String args[])
{
int i = 4, j = 2;
leftshift(i, j);
System.out.println(i);
}
}
16
Correct Answer: - B
4
Q23:-
class A{
int a = 100;
void m1(){
int a;
System.out.println(a);
}
public static void main(String arg[]){
new A().m1();
}
}
10
Compilation Fails
Q24:-
class A{
public static void main(String arg[]){
int ar1[] = null;
ar1 = new int[5];
System.out.println(ar1[0]);
ar1 = new int[]{1,2,3,4,5};
System.out.println(ar1[0]);
}
}
01
00
Compilation Fails
Exception at Runtime
Correct Answer: - A
01