Thomas SMETS
Posts: 307
Nickname: tsmets
Registered: Apr, 2002
|
|
Re: Constructor
|
Posted: Dec 12, 2002 4:41 PM
|
|
First remark is : Respect of other people means that you could at least take 30 secs to read how to post properly. Just thinking that somebody is gonna help is certainly not enough... You should try to make our life easier too
The B class will never compile as it is using the default constructor of A (namely the A ( ) constructor). That constructor has been "disabled" because you defined one your self. As you instanciates B, the very first statement executed in the constructor is in fact a hidden super ();
. The following code herebelow hould work class A
{
int i,j;
/* Removing these comments should also work */
// A () {}
A ( int a, int b)
{
i=a;
j=b;
}
public String toString ()
{
return "i="+i+",j="+j; // Working but incorrect implementation.
}
}
class B
extends A
{
B ( int a, int b)
{
super (a, b); // You refere the right constructor
}
}
class obj
{
public static void main(String rags[])
{
B b=new B(122,555);
System.out.println("B= " + b);
}
}
Ooooooooh, BTW this is not a Design problem but simply a coding problem !
Rgds,
Thomas,
|
|