IntelliJ Java IDE
The moose likes Mock Exam Errata and the fly likes Mock #28 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Mock Exam Errata
Reply Bookmark "Mock #28" Watch "Mock #28" New topic
Author

Mock #28

Netla Reddy
Greenhorn

Joined: Jun 18, 2000
Posts: 15
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

Joined: Aug 25, 2000
Posts: 11
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
But when I tried to compile this is giving a problem
Please Help
rahul pathak
Greenhorn

Joined: Aug 24, 2000
Posts: 11
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
the answer will be a.As class variables get initialised to their default values when they are instantiated.
Regards
Vasudevan v k
 
 
subject: Mock #28
 
Threads others viewed
JTest and char initialization
(again) Implicit conversion question
Assignment
Mock #2 and Question #28
Implicit Conversion?
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture