different inheritence depending on package

F

Frank Fredstone

What am I doing wrong here. These classes in 3 separate files, compile:

// SuperValue.java
public enum SuperValue { A, B; }

// Super.java
public abstract class Super {
abstract SuperValue method();
}

// Sub.java
public class Sub extends Super {
public SuperValue method() { return SuperValue.A; }
}


but, if I put them in packages:


// test/SuperValue.java
package test;
public enum SuperValue { A, B; }

// test/Super.java
package test;
public abstract class Super {
abstract SuperValue method();
}

// test/sub/Sub.java
package test.sub;
import test.SuperValue;
import test.Super;
public class Sub extends Super {
public SuperValue method() { return SuperValue.A; }
}

javac complains that Sub is not abstract and does not override method method.
 
M

Manish Pandit

Hi Frank,

This is because the abstract method you declared is default (package)
scoped. It is not visible outside the current package. If you change
the signature from

abstract SuperValue method();

to public abstract SuperValue method();

it will compile and work fine.

-cheers,
Manish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top