<java>wight affiche pas
domxaline
-
domxaline -
domxaline -
Bonjour,
j'ai essayé ce prg,dans le résultat weight affiche pas
j'ai une erreur suivant
The method weight() is undefined for the type SpecialCube
The method weight() is undefined for the type SpecialCube
at Essaie.Rectangle.main(Rectangle.java:9)
mon prg est suivant:
j'ai essayé ce prg,dans le résultat weight affiche pas
j'ai une erreur suivant
The method weight() is undefined for the type SpecialCube
The method weight() is undefined for the type SpecialCube
at Essaie.Rectangle.main(Rectangle.java:9)
mon prg est suivant:
public class Cube1
{
int length;
int breadth;
int height;
public int getVolume()
{
return (length*breadth*height);
}
Cube1()
{
this(10,10);
System.out.println("Finished with default constructor");
}
Cube1(int l,int b)
{
this(l,b,10);
System.out.println("Finished with parameterized constructor having 2 params");
}
Cube1(int l,int b,int h)
{
length=l;
breadth=b;
height=h;
System.out.println("Finished with parameterized constructor having 3 params");
}
}
package Essaie;
public class SpecialCube extends Cube1
{
int weight;
SpecialCube()
{
super();
weight=10;
}
SpecialCube(int l,int b)
{
this(l,b,10);
System.out.println("Finished with parameterized constructor having 2 params of SpecialCube");
}
SpecialCube(int l, int b,int h)
{
super(l,b,h);
weight=20;
System.out.println("Finished with parameterized constructor having 3 params of SpecialCube");
}
}
package Essaie;
public class Rectangle
{
public static void main(String[]args)
{
SpecialCube specialObj1=new SpecialCube();
SpecialCube specialObj2=new SpecialCube(10,20);
System.out.println("volume of SpecialCube1 is:"+specialObj1.getVolume());
System.out.println("weight of SpecialCube1 is:"+specialObj1.weight());
System.out.println("volume of SpecialCube2 is:"+specialObj2.getVolume());
System.out.println("weight of SpecialCube2 is:"+specialObj2.weight());
}
}
aidez moi s'il vous plait
A voir également:
- <java>wight affiche pas
- Jeux java itel - Télécharger - Jeux vidéo
- Waptrick java football - Télécharger - Jeux vidéo
- Waptrick java voiture - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Eclipse java - Télécharger - Langages
3 réponses
non, j'attends un résultat comme ceci:
Finished with parameterized constructor having 3 params of SpecialCube
Finished with parameterized constructor having 2 params of SpecialCube
volume of SpecialCube1 is:1000
weight of SpecialCube1 is:10
volume of SpecialCube1 is:2000
weight of SpecialCube1 is:20
Finished with parameterized constructor having 3 params of SpecialCube
Finished with parameterized constructor having 2 params of SpecialCube
volume of SpecialCube1 is:1000
weight of SpecialCube1 is:10
volume of SpecialCube1 is:2000
weight of SpecialCube1 is:20
je suis d'accord mais tu n'a pas ecrit ta méthode getWeigt() faudrait rajouter dans specialcube :
public int getWeight(){
return weight;
}
et ensuite remplacer :
System.out.println("weight of SpecialCube1 is:"+specialObj1.getWeight());
System.out.println("weight of SpecialCube2 is:"+specialObj2.getWeight());
public int getWeight(){
return weight;
}
et ensuite remplacer :
System.out.println("weight of SpecialCube1 is:"+specialObj1.getWeight());
System.out.println("weight of SpecialCube2 is:"+specialObj2.getWeight());