Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
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:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Will it compile.?
Akash Trivedi
Greenhorn
Posts: 18
1
I like...
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class Electronic implements Device { public void doIt() { } } abstract class Phone1 extends Electronic { } abstract class Phone2 extends Electronic { public void doIt(int x) { } } class Phone3 extends Electronic implements Device { public void doStuff() { } } interface Device { public void doIt(); }
Shouldn't a method after line 7 needs to implement the doIt() method which Phone3 inherits from Electronics ?
Beware of compiler!
Knute Snortum
Sheriff
Posts: 7125
184
I like...
posted 7 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
Welcome to the Ranch.
Class
Phone2
does
implement the method
doIt()
, don't you think?
Note on your post:
You should
use code tags
to surround your code to make it look better. I did it for you this time. Follow the link to learn more.
All things are lawful, but not all things are profitable.
Tim Moores
Saloon Keeper
Posts: 7582
176
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm not sure what you mean. All 4 classes have the method that implements the interface.
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If you have a compiler, there's a very easy way to find out.
Fred Kleinschmidt
Bartender
Posts: 732
10
posted 7 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
Everything is ok as written. But things change if Electronic is made abstract and its doit() method is declared abstract.
Akash Trivedi
Greenhorn
Posts: 18
1
I like...
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks for the answer. I think, the
Electronic
class
implemented
the
doIt()
method which
Phone3
class
inherited
.So it does
implement
. :E
Beware of compiler!
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Chapter 1 SelfTest question 6
Interface coding doubt
Interface problem
interface problem
K&B7 Chapter 1 Self-test Question 6 (CH1Q6)
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...