It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 1 error when compiling PlayCode.java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "1 error when compiling PlayCode.java" Watch "1 error when compiling PlayCode.java" New topic
Author

1 error when compiling PlayCode.java

Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
Hi all, I got this error - "cannot resolve symbol ... myInterfaceReference.sayHelloFromMyClass()". Any comments would be great!


[ July 19, 2006: Message edited by: Shanel Jacob ]
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
It is true that the return type of the method getMyClass() is MyInterface, and MyClass implements MyInterface.

However, the method sayHelloFromMyClass() is not a member of MyInterface, so unless you cast myInterfaceReference to a MyClass reference, or add the method header of sayHelloFromMyClass() to MyInterface, you can't call sayHelloFromMyClass() with myInterfaceReference.
[ July 19, 2006: Message edited by: Keith Lynn ]
Daniel Bryant
Ranch Hand

Joined: Jul 15, 2006
Posts: 54
I totally agree with Keith. I think what you mean to code was



or if you wanted to explore the casting Keith mentioned you could alter your main method to:




Daniel


SCJP 1.4,<br />SCJD (URLyBird 1.2.1, JDK 5.0)
Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
Hi Keith and Daniel, I tried both suggested fix and managed to compile without errors. Thank you very much (again!)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: 1 error when compiling PlayCode.java