0

Okay, so I've got my directories in IntelliJ like this:

  • src has Main class and a Shape class
  • src\Shapes has Triangle and Square class

Now, in f.e Triangle would look like this:

package Shapes;

public class Triangle extends Shape {
    public double half;
    public Triangle(Double a, Double b, Double c){
        Edges.add(a); Edges.add(b); Edges.add(c);
        for (Double edge:
             Edges) {
            half+=edge/2.0;
        }
    }
    public double Surface(){
        return Math.sqrt(half*(half-Edges.get(0))*(half-Edges.get(1))*(half-Edges.get(2)));    
    }
}

It looked like this and it worked just before I made Shapes dir and I moved Triangle and Square there. So now, how can I make this class extend a class which is in a previous directory?

That's the structure:

enter image description here

minecraftplayer1234
  • 2,127
  • 4
  • 27
  • 57
  • 1
    To avoid this kind of problem always place your classes in specific packages, not default one. So move your `Shape` to `Shapes` package (and rename that package to not include any uppercase characters like naming convention suggests). – Pshemo Jul 03 '16 at 22:40
  • Could you please show your directory/package structure. I am unclear on your exact setup. It sounds like you have Triangle and Square inside a Shapes package and the Shape class under the src/ directory? – DecafCoder Jul 03 '16 at 22:43
  • This is the structure: https://i.gyazo.com/d36e30652cb0ec9f403ae6e2df4263ca.png – minecraftplayer1234 Jul 03 '16 at 22:49
  • Actually, maybe this will be better duplicates: [How to access java-classes in the default-package?](http://stackoverflow.com/questions/283816/how-to-access-java-classes-in-the-default-package) OR [How to import a class from default package](http://stackoverflow.com/questions/2193226/how-to-import-a-class-from-default-package) – Pshemo Jul 03 '16 at 22:56

0 Answers0