Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Programmer Certification (OCPJP)
Inner Classes Mock question doubt
Hardik Raja
Ranch Hand
Posts: 117
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello Friends,
This is a question from K & B Book, Chapter Inner classes, Page 666
WHY OPTION D IS INCORRRECT..??
3. Given: public interface Runnable { void run(); } Which construct an anonymous inner class instance? (Choose all that apply.) A. Runnable r = new Runnable() { }; B. Runnable r = new Runnable(public void run() { }); C. Runnable r = new Runnable { public void run(){}}; D. Runnable r = new Runnable() {public void run{}}; E. System.out.println(new Runnable() {public void run() { }}); F. System.out.println(new Runnable(public void run() {})); Answer: E is correct. It defines an anonymous inner class instance, which also means it creates an instance of that new anonymous class at the same time. The anonymous class is an implementer of the Runnable interface, it must override the run() method of Runnable. A is incorrect because it doesn't override the run() method, so it violates the rules of interface implementation. B, C, and D use incorrect syntax.
Can anyone please give their suggestions on the above problem.Thank you in advance.
Regards,
Hardik.S.Raja
Chandra Bhatt
Ranch Hand
Posts: 1710
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Hardik,
See the option 'D' separately:
D. Runnable r = new Runnable() {public void run{}};
Now did you get, what error is there?
I hope you got that!
cmbhatt
Nik Arora
Ranch Hand
Posts: 652
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Whats your doubt exactly. What are you not understanding in that.
Hardik Raja
Ranch Hand
Posts: 117
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi chandra bhatt,
Now did you get, what error is there?
I think there is no error....It perfectly defines an anonymous class that implements Runnable and also fulfills its contract by implementing run().
Is it a Printing mistake in Book..??
hardik
[ May 04, 2007: Message edited by: Hardik Raja ]
Abdul Mohsin
Ranch Hand
Posts: 111
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Error is in brackets {} it should be () and then {}
Regards, Abdul Mohsin
Hardik Raja
Ranch Hand
Posts: 117
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Oh my god...
Hey guys I am sorry for asking such a stupid question...
Anyways got it......Thanks...
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
K&B Pg 666 Answer to Question #3
Anonymous Inner Class
K&B Chapter 8: Inner Classes - Self Test
Anonymous class
K & B: Inner Classes Self-Test
More...