(1)
public class This {
public static void main(String[] args) {
int a=5,b=10,c=8;
long s=a>b?c:a>c?b=+b++:++b;
System.out.print(s);
}
}
What will output when you compile and run the above code?
(a)11
(b)21
(c)20
(d)Compiler error
Answer: (a)
(2)
public class BreakDemo {
public static void main(String[] args){
String[][]alpha={{"a"},{"b","c"}};
for(String str[]:alpha)
{
for(String s:str)
{
System.out.print(s+" ");
if(s.equals("b")) return;
}
}
}
}
What will be output of above program?
(a)a null
(b)a null b
(c)a b
(d)Compiler error
Answer:(c)
(3)What will be output of following program?
public class Datatype {
public static void main(String[] args) {
byte b=125;
b=(byte)(b*2);
System.out.println(b);
}
}
(a)15
(b)12
(c)9
(d)6
Answer: ()
(4) Which of the following is not primitive data type?
(a) int
(b) char
(c) String
(d) double
Answer: (c)
Explanation:
String is not a keyword of java. It is class of java which has been defined in java.lang.String
(5)
class Operator
{
public static void main(String[] args)
{
int a=5;
int c=0;
c=+-a+++a;
System.out.println(c);
}
}
What will output when you compile and run the above code?
(a)0
(b)1
(c)-11
(d)Compiler error
Answer: (b)