(1)
public class Loop {
public static void main(String[] args){
int i=0;
boolean b=true;
for(i++;b;i++)
{
System.out.println(~i);
b^=true;
}
}
}
What will be output of above program?
(a)-2
(b)-3
(c)Infinite loop
(d)Compiler error
Answer: (a)
(2)
public class ClassDemo {
public static void main(String[] args){
ClassDemo o=new ClassDemo();
o.cal(5,10,15);
}
void cal(byte p,byte q,byte r)
{
System.out.print(p+q+r);
}
}
What will be output of above program?
(a)30
(b)30b
(c)30B
(d)Compiler error
Answer: (d)
(3)
public class Literal {
public static void main(String[] args) {
int a ='\u0041';
int b='\15';
int c=a+b;
System.out.println(c);
}
}
What will output when you compile and run the above code?
(a)56
(b)4115
(c)78
(d) Compiler error
Explanation: (c)
(4)
class BitwiseOperator
{
public static void main(String[] args)
{
byte a=-10,b=0;
b=a>>2;
System.out.println(b);
}
}
What will output when you compile and run the above code?
(a)-40
(b)-2
(c)2
(d)Compiler error
Answer: (d)
(5)
package raja;
public class World {
boolean b=false^false;
Boolean c=!true;
}
package manish;
import raja.World;
class AccessControl {
public static void main(String[] args){
World w=new World();
System.out.print(w.b+","+w.c);
}
}
What will be output of above program?
(a)false,false
(b)true,false
(c)true,true
(d)Compiler error
Answer: (d)
(6)
public class Loop {
public static void main(String[] args){
int i=0;
int j=5;
boolean b=true;
for(i++,--j;b;)
{
System.out.println(~i-~j);
b^=true;
}
}
}
What will be output of above program?
(a)3
(b)4
(c)Infinite loop
(d)Compiler error
Answer: (a)
(7)
public class ClassDemo {
public static void main(String[] args){
ClassDemo o=new ClassDemo();
o.cal(5,10,15);
}
void cal(short p,short q,short r)
{
System.out.print(~p+~q+~r);
}
}
What will be output of above program?
(a)-33
(b)-30
(c)-33h
(d)Compiler error
Answer: (d)
(8)
public class Literal {
public static void main(String[] args) {
int a=010+0x20+'\10'+'\u0020';
System.out.println(a);
}
}
(a)60
(b)2040
(c)80
(d) Compiler error
Answer: (c)
Explanation:
(9)
class BitwiseOperator
{
public static void main(String[] args)
{
byte a=-10;
int b=a>>2;
int c=a>>>2;
System.out.println("a= "+a+" b="+b+" c="+c);
}
}
What will output when you compile and run the above code?
(a) a=-10 b=-3 c=1073741821
(b) a=-3 b=-3 c=-3
(c) a=-10 b=-3 c=-3
(d)Compiler error
Answer: (a)
(10)
package raja;
public class World {
public boolean b=false^false;
public Boolean c=!true;
}
package manish;
import raja.World;
class AccessControl {
public static void main(String[] args) {
World w=new World();
System.out.print(w.b+","+w.c);
}
}
What will be output of above program?
(a)true,true
(b)false,false
(c)true,false
(d)Compiler error
Answer: (b)
(11)
public class Loop {
public static void main(String[] args){
int i=0;
int j=05;
for(i++,--j;j>0;)
{
System.out.println(j>>>i);
--j;
}
}
}
What will be output of above program?
(a)2
1
1
0
(b)2
0
(c)2
0
0
(d)Compiler error
Answer:(a)
(12)
public class ClassDemo {
public static void main(String[] args){
ClassDemo o=new ClassDemo();
o.cal(5,10,15);
}
void cal(short p,short q,short r)
{
System.out.print(~p+~q+~r);
}
}
What will be output of above program?
(a)-33
(b)-30
(c)-33h
(d)Compiler error
Answer: (d)
(13)What will be output of following program?
class StringLiteral
{
public static void main(String[] args)
{
String str="india\11usa";
System.out.println(str);
}
}
What will output when you compile and run the above code?
(a)India\11usa
(b)India usa
(c)india
(d)Compiler error
Answer: (b)
(14)
public class UnaryOperator {
public static void main(String[] args) {
int j=5;
j=++j + j++ + ++j;
System.out.print(j);
}
}
What will output when you compile and run the above code?
(a)18
(b)19
(c)20
(d)21
Answer: (c)
(15)
package raja;
class World {
public boolean b=false^false;
public Boolean c=!true;
}
Package manish;
import raja.World;
class AccessControl {
public static void main(String[] args) throws Exception {
World w=new World();
System.out.print(w.b+","+w.c);
}
}
What will be output of above program?
(a)false,false
(b)true,false
(c)true,true
(d)Compiler error
Answer: (d)
Responses
0 Respones to "Java question answer"
Post a Comment