Java :erreur de compilation
domxaline
-
KX Messages postés 16761 Date d'inscription Statut Modérateur Dernière intervention -
KX Messages postés 16761 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour,
j'ai une erreur lors de compilation,veuillez aidez moi svp
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
FigureObject cannot be resolved to a type
FigureObject cannot be resolved to a type
at RectangleObject.main(RectangleObject.java:10)
j'ai une erreur lors de compilation,veuillez aidez moi svp
abstract public class Figure { int x,y; void changePosition (int newX,int newY) { } abstract void draw(); {} } public class CirculeObject extends Figure { void draw() { System.out.println("Draw method called"); } } public class RectangleObject extends Figure { void changePosition(int newX,int newY) { System.out.println("change position method called"); } public static void main(String[]args) { FigureObject f0=new FigureObject(20,15); f0.draw(); CirculeObject f1=new CirculeObject(); f1.draw(); RectangleObject f2=new RectangleObject() ; f2.changePosition(10,20); } }
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
FigureObject cannot be resolved to a type
FigureObject cannot be resolved to a type
at RectangleObject.main(RectangleObject.java:10)
A voir également:
- Java :erreur de compilation
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
8 réponses
Si draw est abstraite dans Figure alors :
1) Tu ne dois pas mettre d'accolades derrière.
2) Tu dois définir la méthode draw dans RectangleObject sinon elle sera également abstraite et tu ne pourra pas faire d'instanciation (new RectangleObject)
1) Tu ne dois pas mettre d'accolades derrière.
2) Tu dois définir la méthode draw dans RectangleObject sinon elle sera également abstraite et tu ne pourra pas faire d'instanciation (new RectangleObject)
vous voulez que je fasse comme ça
j'ai toujours la même erreur
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
FigureObject cannot be resolved to a type
FigureObject cannot be resolved to a type
The method changePosition() in the type Figure is not applicable for the arguments (int, int)
at RectangleObject.main(RectangleObject.java:11)
abstract public class Figure { int x,y; void changePosition (int new x,int new y) { } abstract void draw(); } public class RectangleObject extends Figure { //void changePosition(int newX,int newY) void draw(int newX,int newY) { System.out.println("change position method called"); } public static void main(String[]args) { FigureObject f0=new FigureObject(20,15); f0.draw(); CirculeObject f1=new CirculeObject(); f1.draw(); RectangleObject f2=new RectangleObject() ; f2.changePosition(10,20); } }
j'ai toujours la même erreur
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
FigureObject cannot be resolved to a type
FigureObject cannot be resolved to a type
The method changePosition() in the type Figure is not applicable for the arguments (int, int)
at RectangleObject.main(RectangleObject.java:11)
abstract public class Figure
{
int x,y;
void changePosition (int new x,int new y)
{
}
abstract void draw();
}
{
int x,y;
void changePosition (int new x,int new y)
{
}
abstract void draw();
}
le correction
public class RectangleObject extends Figure
{
void changePosition(int newX,int newY)
void draw(int newX,int newY)
{
System.out.println("change position method called");
}
public static void main(String[]args)
{
Figure f0=new Figure(20,15);
f0.draw();
CirculeObject f1=new CirculeObject();
f1.draw();
RectangleObject f2=new RectangleObject() ;
f2.changePosition(10,20);
}
}
public class RectangleObject extends Figure
{
void changePosition(int newX,int newY)
void draw(int newX,int newY)
{
System.out.println("change position method called");
}
public static void main(String[]args)
{
Figure f0=new Figure(20,15);
f0.draw();
CirculeObject f1=new CirculeObject();
f1.draw();
RectangleObject f2=new RectangleObject() ;
f2.changePosition(10,20);
}
}
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
en générale la sous classe devient abstraite l'orque elle contient une méthode abstraite au fait je vous demande est ce qu'il y a d'autre cas dans le qu'elle la sous classe sois abstraite
abstract public class Figure { int x,y; void changePosition (int x,int y) { } abstract void draw() }
public abstract class CirculeObject extends Figure { void draw() { System.out.println("Draw method called"); } }
public abstract class RectangleObject extends Figure { void changePosition(int newX,int newY) void draw(int newX,int newY) { System.out.println("change position method called"); } public static void main(String[]args) { Figure f0=new Figure(20,15); f0.changePosition(); CirculeObject f1=new CirculeObject(); f1.draw(); RectangleObject f2=new RectangleObject() ; f2.changePosition(10,20); } }
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot instantiate the type Figure
The method changePosition(int, int) in the type Figure is not applicable for the arguments ()
Cannot instantiate the type CirculeObject
Cannot instantiate the type RectangleObject
at RectangleObject.main(RectangleObject.java:11)
public abstract class RectangleObject extends Figure { void changePosition(int newX,int newY) void draw(int newX,int newY) { System.out.println("change position method called"); } public static void main(String[]args) { Figure f0=new Figure(); f0.changePosition(20,15); CirculeObject f1=new CirculeObject(); f1.draw(); RectangleObject f2=new RectangleObject() ; f2.changePosition(10,20); } }
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot instantiate the type Figure
Cannot instantiate the type CirculeObject
Cannot instantiate the type RectangleObject
at RectangleObject.main(RectangleObject.java:11)
bonjour j'ai corrigé mon prg ainsi mais toujous j'ai une erreur
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot instantiate the type CirculeObject
newX cannot be resolved to a variable
newY cannot be resolved to a variable
Cannot instantiate the type RectangleObject
x cannot be resolved to a variable
y cannot be resolved to a variable
at AbstractEssaie.main(AbstractEssaie.java:6)
abstract public class Figure { int x,y; void changePosition (int newX,int newY) { } abstract void draw(); }
public abstract class CirculeObject extends Figure { void draw() { System.out.println("Draw method called"); } }
public abstract class RectangleObject extends Figure { void changePosition(int newX,int newY) { System.out.println("change position method called"); } }
public class AbstractEssaie { public static void main(String[]args) { CirculeObject c=new CirculeObject(); Figure figuref; figuref=c; System.out.println("CirculeObject is"+figuref.changePosition(newX,newY)); RectangleObject r =new RectangleObject(); figuref=r; System.out.println("RectangleObject is"+figuref.draw(x,y)); } }
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot instantiate the type CirculeObject
newX cannot be resolved to a variable
newY cannot be resolved to a variable
Cannot instantiate the type RectangleObject
x cannot be resolved to a variable
y cannot be resolved to a variable
at AbstractEssaie.main(AbstractEssaie.java:6)