Powwow.java:16: error: wow() in Wow cannot implement wow() in Pow
public class Powwow extends Wow implements Pow {
^
overriding method is static
1 error
Powwow.java:13: error: wow() in Wow cannot implement wow() in Pow
public class Powwow extends Wow implements Pow {
^
attempting to assign weaker access privileges; was public
1 error
Shane Jensen wrote:
1) The error states that Wow's (the abstract class) method is trying to implement Pow's (the interface) method. I don't understand where this is coming from though. Wow does not implement the interface Pow, so aren't these two methods separate? I did notice that if I comment out f.wow(), the code does compile. It obviously has something to do with the way the method is called, but I can't figure out what it is.
Shane Jensen wrote:
3) Again, it seems that Wow's method is trying to override Pow's method, since it's access modifier has now gone from public to default, which isn't allowed. I suppose this compilation failure pertains to the same issue as brought up in my first question, right?
Henry Wong wrote:
Shane Jensen wrote:
1) The error states that Wow's (the abstract class) method is trying to implement Pow's (the interface) method. I don't understand where this is coming from though. Wow does not implement the interface Pow, so aren't these two methods separate? I did notice that if I comment out f.wow(), the code does compile. It obviously has something to do with the way the method is called, but I can't figure out what it is.
The Wow class does *not* implement the Pow interface, however, the Powwow class must implement the Pow interface (as it is declared to do so). Unfortunately, according to section 8.4.8.1 of the JLS, this is not allowed...
https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.8.1
as doing so will have an instance method trying to override a static method.
Henry
Shane Jensen wrote:
Regarding my second question: I don't understand why a static method is not allowed to override a non-static method.
Henry Wong wrote:
Shane Jensen wrote:
Regarding my second question: I don't understand why a static method is not allowed to override a non-static method.
Overriding does not apply to static methods. It is for instance methods, that are accessible. So... the answer to the question is, no, overridding does not apply for static methods. Period.
But that is not what you are asking here. You are asking whether it compiles or not -- or at least, that is how I answered it.
Henry
Powwow.java:16: error: wow() in Wow cannot implement wow() in Pow
public class Powwow extends Wow implements Pow {
^
overriding method is static
1 error
Shane Jensen wrote:
True. So then my question would be: why does the following error occur? The method in the class is static, while the method in the interface is non-static. But why is that a problem?
Powwow.java:16: error: wow() in Wow cannot implement wow() in Pow
public class Powwow extends Wow implements Pow {
^
overriding method is static
1 error
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
|