IntelliJ Java IDE
The moose likes Mock Exam Errata and the fly likes doubts from the john hunt's mock test Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Mock Exam Errata
Reply Bookmark "doubts from the john hunt Watch "doubts from the john hunt New topic
Author

doubts from the john hunt's mock test

rajani peddi
Ranch Hand

Joined: Nov 27, 2000
Posts: 73
i have a few doubts in john hunt's test. http://www.javaranch.com/maha/_Mock_Exams/JohnJuntMockExam.htm
1.Which variables can an inner class access from the class which encapsulates it?
a) All static variables
b) All final variables
c) All instance variables
d) Only final instance variables
e) Only final static variables
Select all correct answers.

the answer given is a,b,c. but i think that its only c.

2.Which of the following correctly illustrate how an InputStreamReader can be created:
a) new InputStreamReader(new FileInputStream("data"));
b) new InputStreamReader(new FileReader("data"));
c) new InputStreamReader(new BufferedReader("data"));
d) new InputStreamReader("data");
e) new InputStreamReader(System.in);
Select all correct answers.
the answers given are a,e. but i answered as b,e
correct me if i am wrong

3.What is the result of compiling and executing the following Java class:
public class ThreadTest extends Thread {
public void run() {
System.out.println("In run");
suspend();
resume();
System.out.println("Leaving run");
}

public static void main(String args []) {
(new ThreadTest()).start();
}
}

a) Compilation will fail in the method main.
b) Compilation will fail in the method run.
c) A warning will be generated for method run.
d) The string "In run" will be printed to standard out.
e) Both strings will be printed to standard out.
f) Nothing will happen.
Select the most appropriate answer.
what is the answer and why?
Bharatesh H Kakamari
Ranch Hand

Joined: Nov 09, 2000
Posts: 198
Answers :
1.Which variables can an inner class access from the class which encapsulates it?
the answer given is a,b,c.
2.
Refer : http://www.jchq.net/discus/messages/1/20387.html?975462558
InputStreamReader does not have any constructor to take a FileReader as parameter. Hence b is wrong.
3.
The answer is 'd'. Once a thread is suspended it cannot resume itself because it is in the suspended state. It is only some other thread that thas to resume this thread.
rajani peddi
Ranch Hand

Joined: Nov 27, 2000
Posts: 73
thank u Bharatesh. i got the last two. can you explain the first one?
an inner class can access only final variables if it is inside a method. similarly it can access only static variables if it is a static inner class. otherewise it can access all instance variables, isn't?
so the answer should be c
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
What you said is correct in that inner classes inside of methods can only access final variables in the method and static inner classes can only access static variables, but the question doesn't say it is an inner class defined in a method or that it is static.
So if it is just a non-static inner class, then they can access all final variables, static variables, and instance variables with no problems. The only variables they can't access are variables local to methods.
rajani peddi
Ranch Hand

Joined: Nov 27, 2000
Posts: 73
thanks bill....its clear now
Mugdha Deo
Greenhorn

Joined: Nov 30, 2000
Posts: 13

Aren't suspend and resume methods depricated?
So, shouldn't the answer be c ?
Thanks,
Mugdha.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
suspend() and resume() are deprecated, and the java 2 exam shouldn't ask you questions on this. However, you can still use them, so it will compile. I wouldn't worry much about those questions, since you shouldn't see them.
Bill
 
 
subject: doubts from the john hunt's mock test
 
Threads others viewed
John Hunt Mock Exam: Q34
Thread
HUNT's mock exam
HUNT's mock exam...pls..help
two from Hunt's
developer file tools

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