• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock #28

 
Netla Reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please could you some body give the answer.?

Question 28)
What will happen when you attempt to compile and run the following code
public class As{
int i = 10;
int j;
char z= 1;
boolean b;
public static void main(String argv[]){
As a = new As();
a.amethod();
}
public void amethod(){
System.out.println(j);
System.out.println(b);
}
}
1) Compilation succeeds and at run time an output of 0 and false
2) Compilation succeeds and at run time an output of 0 and true
3) Compile time error b is not initialised
4) Compile time error z must be assigned a char value

Given Ans is 1:
But I belive that answer is 4;
Thanks in advance
 
musa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ans 1 is right
the ascii value of char is taken.
So 1 is converted to its ascii value.


[This message has been edited by musa (edited September 06, 2000).]
 
Netla Reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when I tried to compile this is giving a problem
Please Help
 
rahul pathak
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there should not be problem as b being a instance variable is initallized to false
 
v k vasudevan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the answer will be a.As class variables get initialised to their default values when they are instantiated.
Regards
Vasudevan v k
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic