demande conseil sur ce prg
bonjour
j'ai essayé ce prg suivant
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
package Essaie;
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=10;
breadth=10;
height=10;
System.out.println("Finished with parameterized constructor having 3 params");
}
}
package Essaie;
public class Rectangle
{
public static void main(String[]args)
{
Cube1 cubeObj1,cubeObj2;
cubeObj1=new Cube1();
cubeObj2=new Cube1(10,20,30);
System.out.println("volume of Cube1 is:"+cubeObj1.getVolume());
System.out.println("volume of Cube2 is:"+cubeObj2.getVolume());
}
} |
le output ce ce prg est le suivant
Finished with parameterized constructor having 3 params
Finished with parameterized constructor having 2 params
Finished with default constructor
Finished with parameterized constructor having 3 params
volume of Cube1 is:1000
volume of Cube2 is:6000
mes questions sont suivantes:
1.pourquoi output est désordonné, (au lieu de avoir comme ceci)
Finished with default constructor
Finished with parameterized constructor having 2 params
Finished with parameterized constructor having 3 params
2.et pourquoi j'ai deux fois la ligne suivante dans l'output?
Finished with parameterized constructor having 3 params