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
Joined: Aug 25, 2000
Posts: 11
posted
0
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
Joined: Jun 18, 2000
Posts: 15
posted
0
But when I tried to compile this is giving a problem Please Help
rahul pathak
Greenhorn
Joined: Aug 24, 2000
Posts: 11
posted
0
there should not be problem as b being a instance variable is initallized to false
v k vasudevan
Greenhorn
Joined: Sep 11, 2000
Posts: 1
posted
0
the answer will be a.As class variables get initialised to their default values when they are instantiated. Regards Vasudevan v k