Does import with wildcard behave differently with user package

Sab
 //With these I am getting compilation - error class not found 
 /*import Shape.TwoD.*;
 import Shape.ThreeD.*;
 import Shape.*;*/

 import Shape.TwoD.Circle;
 import Shape.TwoD.Line;
 import Shape.ThreeD.Line3D;
 import Shape.ThreeD.Sphere;
 import Shape.Actions;

public class Test {

    /**
     * Creates a new instance of <code>Test</code>.
     */
     int o;
    public Test() {

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Actions obj[] = new Actions[4];
        obj[0] = new Line(1,2,3,4);
        obj[1] = new Circle(1,2,3);
        obj[2] = new Line3D(1,2,3,4,5,6);
        obj[3] = new Sphere(1,2,3,4);
        for(Actions x: obj)
            x.draw();
        Actions.TwoD o =(Circle)obj[1];
        System.out.println("Area of circle "+o.area());
        o = (Sphere)obj[3];
        System.out.println("Volume of sphere "+o.area());
    }
}

Action is an interface which contains nested interface TwoD and ThreeD

Why import with wildcard not working in the above code? Am I using it wrong?

I couldn't find any related answer, if both wildcard and fully qualified imports are not working then there is problem in my code but in this case, compilation error occur class not found only when I use wildcard with import.

EDIT: Sorry for the wrong naming convention, Line,Circle,Line3D and Sphere are the classes Lineand Circle comes under Shape.TwoD

Line3D and Sphere comes under Shape.ThreeD

Actions.java:

package Shape;

public interface Actions {

        interface ThreeD{
            double volume();
        }

        interface TwoD{
            double area();
        }

        void draw();
        //void erase();
        final double pi = 3.142857;

}

Line.java:

    package Shape.TwoD;

public class Line implements Shape.Actions{

    BaseObj.Point p1,p2;

    public Line(int x1,int y1, int x2 ,int y2) {
        p1 = new BaseObj.Point(x1,y1);
        p2 = new BaseObj.Point(x2,y2);
    }

    public void draw(){
        //System.out.println("Line between ("+p1.x+","+p1.y+") and ("+p2.x+","+p2.y+"));
        System.out.println("Line between ("+p1.getx()+","+p1.gety()+") and ("+p2.getx()+","+p2.gety()+") has been drawn");
    }

}

Circle.java:

package Shape.TwoD;

public class Circle extends BaseObj.Point implements Shape.Actions, Shape.Actions.TwoD{

    protected int radius;

    public Circle(int x, int y, int radius) {
        super(x,y);
        this.radius = radius;
    }

    public void draw(){
        System.out.println("Circle with ("+x+","+y+") as center and radius "+radius+" units has been drawn");
    }

    public double area(){
        return (pi*radius*radius);
    }

}

Line3D.java:

package Shape.ThreeD;
public class Line3D  implements Shape.Actions {

    BaseObj.Point3D p1,p2;

    public Line3D(int x1,int y1, int z1, int x2,int y2, int z2) {
        p1 = new BaseObj.Point3D(x1,y1,z1);
        p2 = new BaseObj.Point3D(x2,y2,z2);
    }

    public void draw(){
        //System.out.println("Line between ("+p1.x+","+p1.y+") and ("+p2.x+","+p2.y+"));
        System.out.println("Line between ("+p1.getx()+","+p1.gety()+","+p1.getz()+") and ("+p2.getx()+","+p2.gety()+","+p2.getz()+") has been drawn");
    }

}

Sphere.java:

package Shape.ThreeD;
public class Sphere extends Shape.TwoD.Circle{

    int z;

    public Sphere(int x, int y, int z, int radius) {
        super(x,y,radius);
        this.z = z;
    }

    public void draw(){
        System.out.println("Spere with ("+x+","+y+","+z+") as center and radius "+radius+" units has been drawn");
    }

    public double volume(){
        return(radius*radius*pi*4/3);
    }

    public double area(){
        System.out.println("Sphere is a 3D object so 2D quantitys doesnt apply");
        return 0.0;
    }
}

Edit2: After correcting the names I got error that Actions interface is duplicate so I changed its name into ObjActions and the problem resolved. Thanks for the help. I hope the naming convention I used below is consistent with standard.

ObjActions.java

package shape;

public interface ObjActions {

        interface Actions3D{
            double volume();
        }

        interface Actions2D{
            double area();
        }

        void draw();
        //void erase();
        final double pi = 3.142857;

}

Circle.java

package shape.twod;

public class Circle extends baseobj.Point implements shape.ObjActions, shape.ObjActions.Actions2D{

    protected int radius;

    public Circle(int x, int y, int radius) {
        super(x,y);
        this.radius = radius;
    }

    public void draw(){
        System.out.println("Circle with ("+x+","+y+") as center and radius "+radius+" units has been drawn");
    }

    public double area(){
        return (pi*radius*radius);
    }

}

Line.java

package shape.twod;

public class Line implements shape.ObjActions{

    baseobj.Point p1,p2;

    public Line(int x1,int y1, int x2 ,int y2) {
        p1 = new baseobj.Point(x1,y1);
        p2 = new baseobj.Point(x2,y2);
    }

    public void draw(){
        //System.out.println("Line between ("+p1.x+","+p1.y+") and ("+p2.x+","+p2.y+"));
        System.out.println("Line between ("+p1.getx()+","+p1.gety()+") and ("+p2.getx()+","+p2.gety()+") has been drawn");
    }

}

Line3D.java

package shape.threed;

public class Line3D  implements shape.ObjActions {

    baseobj.Point3D p1,p2;

    public Line3D(int x1,int y1, int z1, int x2,int y2, int z2) {
        p1 = new baseobj.Point3D(x1,y1,z1);
        p2 = new baseobj.Point3D(x2,y2,z2);
    }

    public void draw(){
        //System.out.println("Line between ("+p1.x+","+p1.y+") and ("+p2.x+","+p2.y+"));
        System.out.println("Line between ("+p1.getx()+","+p1.gety()+","+p1.getz()+") and ("+p2.getx()+","+p2.gety()+","+p2.getz()+") has been drawn");
    }

}

Sphere.java

package shape.threed;

public class Sphere extends shape.twod.Circle implements shape.ObjActions.Actions3D{

    int z;

    public Sphere(int x, int y, int z, int radius) {
        super(x,y,radius);
        this.z = z;
    }

    public void draw(){
        System.out.println("Spere with ("+x+","+y+","+z+") as center and radius "+radius+" units has been drawn");
    }

    public double volume(){
        return(radius*radius*pi*4/3);
    }

}

Test.java

package test;

 import shape.twod.*;
 import shape.threed.*;
 import shape.*;


 /*import shape.twod.Circle;
 import shape.twod.Line;
 import shape.threed.Line3D;
 import shape.threed.Sphere;
 import shape.Actions;*/

public class Test {

    /**
     * Creates a new instance of <code>Test</code>.
     */
     int o;
    public Test() {

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        ObjActions obj[] = new ObjActions[4];
        obj[0] = new Line(1,2,3,4);
        obj[1] = new Circle(1,2,3);
        obj[2] = new Line3D(1,2,3,4,5,6);
        obj[3] = new Sphere(1,2,3,4);
        for(ObjActions x: obj)
            x.draw();
        ObjActions.Actions2D o =(Circle)obj[1];
        //Actions2D o =(Circle)obj[1];
        System.out.println("Area of circle "+o.area());
        ObjActions.Actions3D op = (Sphere)obj[3];
        System.out.println("Volume of sphere "+op.volume());
    }
}
Thomas

The "packages" TwoD and ThreeD might get shadowed by the interfaces Action.TwoD and Action.ThreeD (or vice versa) as per JLS 7.5.2:

The declaration might be shadowed by a single-type-import declaration of a type whose simple name is Vector; by a type named Vector and declared in the package to which the compilation unit belongs; or any nested classes or interfaces.

The declaration might be obscured by a declaration of a field, parameter, or local variable named Vector.

(It would be unusual for any of these conditions to occur.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Does import with wildcard behave differently with user package

From Dev

Does wildcard characters behave differently?

From Dev

Why does srandom(time(NULL)) behave differently within main() function and that of a user defined function?

From Dev

Why does strptime() behave differently on OSX and on Linux?

From Dev

Why does this array initialize behave differently?

From Dev

Why does this constraint behave differently on different simulators?

From Dev

Why does this contextmanager behave differently with dict comprehensions?

From Dev

Does NetworkStream with StreamWriter behave differently on Linux?

From Dev

Why does FINDSTR behave differently in powershell and cmd?

From Dev

Why does EOF behave differently in fgets and read

From Dev

Why does the complement behave differently through printf?

From Dev

Why does "last" behave differently in Perl in these examples?

From Dev

Why does this code behave differently in NodeJS?

From Dev

Why does "grep" behave differently in this example?

From Dev

Why does this array initialize behave differently?

From Dev

Why does this contextmanager behave differently with dict comprehensions?

From Dev

Why does `==` behave differently inside `[ ... ]` in zsh and bash?

From Dev

Why does strptime() behave differently on OSX and on Linux?

From Dev

Why does /* */ comment behave differently ? Javascript bug?

From Dev

Why does "last" behave differently in Perl in these examples?

From Dev

Why does jQuery behave differently than javascript?

From Dev

Why does to_sym behave differently?

From Dev

Does .prop behave differently for radio buttons?

From Dev

Why does ghci behave differently to runHaskell?

From Dev

Why does SetSystemTime() behave differently in the Afternoons?

From Dev

Why does "include" behave differently in the global context than it does in a class?

From Dev

Why does "include" behave differently in the global context than it does in a class?

From Dev

Java import wildcard not importing everything inside package

From Java

Why does R behave differently when parsing parameters of plotting?

Related Related

  1. 1

    Does import with wildcard behave differently with user package

  2. 2

    Does wildcard characters behave differently?

  3. 3

    Why does srandom(time(NULL)) behave differently within main() function and that of a user defined function?

  4. 4

    Why does strptime() behave differently on OSX and on Linux?

  5. 5

    Why does this array initialize behave differently?

  6. 6

    Why does this constraint behave differently on different simulators?

  7. 7

    Why does this contextmanager behave differently with dict comprehensions?

  8. 8

    Does NetworkStream with StreamWriter behave differently on Linux?

  9. 9

    Why does FINDSTR behave differently in powershell and cmd?

  10. 10

    Why does EOF behave differently in fgets and read

  11. 11

    Why does the complement behave differently through printf?

  12. 12

    Why does "last" behave differently in Perl in these examples?

  13. 13

    Why does this code behave differently in NodeJS?

  14. 14

    Why does "grep" behave differently in this example?

  15. 15

    Why does this array initialize behave differently?

  16. 16

    Why does this contextmanager behave differently with dict comprehensions?

  17. 17

    Why does `==` behave differently inside `[ ... ]` in zsh and bash?

  18. 18

    Why does strptime() behave differently on OSX and on Linux?

  19. 19

    Why does /* */ comment behave differently ? Javascript bug?

  20. 20

    Why does "last" behave differently in Perl in these examples?

  21. 21

    Why does jQuery behave differently than javascript?

  22. 22

    Why does to_sym behave differently?

  23. 23

    Does .prop behave differently for radio buttons?

  24. 24

    Why does ghci behave differently to runHaskell?

  25. 25

    Why does SetSystemTime() behave differently in the Afternoons?

  26. 26

    Why does "include" behave differently in the global context than it does in a class?

  27. 27

    Why does "include" behave differently in the global context than it does in a class?

  28. 28

    Java import wildcard not importing everything inside package

  29. 29

    Why does R behave differently when parsing parameters of plotting?

HotTag

Archive