Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
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:
Java in General
Why don't I have an error here?
Andrew Stallard
Ranch Hand
Posts: 33
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Now, I have this interface called JohnnyNumber:
public interface JohnnyNumber{ double n=1.010101777; public double doSomething(double m); public void doSomethingElse(); }
This interface is implemented by a class called TestOne:
public class TestOne extends TestClass implements JohnnyNumber { double m; public double doSomething(double m){ return Math.pow(m*n,n*m); } public static void main(String[]args){ TestOne Fred=new TestOne(); System.out.println(Fred.doSomething(3.45)); Fred.anInstanceMethod(); Fred.aStaticMethod(); aStaticMethod(); } }
Now, I do not use the method doSomethingElse() in the class even though it is in the interface, but the program runs just fine. What is going on?
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Probably, the *TestClass* implemented the missing method
Andrew Stallard
Ranch Hand
Posts: 33
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here is TestClass. he method do SomethingElse() has not been implemented.
public class TestClass{ public void anInstanceMethod(){ System.out.println("This is an instance method."); } public static void aStaticMethod(){ System.out.println("This is a static method!"); } }
Thanks anyway
bhanu chowdary
Ranch Hand
Posts: 256
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have just tested with your code and the compiler is throwing an error.
"The type TestOne must implement the inherited abstract method JohnnyNumber.doSomethingElse()".
Could you please check again.
Andrew Stallard
Ranch Hand
Posts: 33
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
OK, I have figured it out. I changed (and recompiled) the interface when I added the additional method. However, I did not recompile the TestOne class. (I didn't think I had too because I changed no code.) Upon recompiling, the error appears.
Sorry
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
Reflection
interface help
problem with overloading
Wrapper Class ?
More...