Constructor must have *super* or *this* at the first line.
In your case, you haven't provide any:
code:
--------------------------------------------------------------------------------
public Test2(String str){ System.out.println("Sub class"); }
I don't thing that was the reason behind the compiler error.
if we do not implicitly write super() or this() as the first argument in a constructor then the compiler itself will insert & call the super().
So, my friend Karthik Rajashekaran , the main problem is you have written a constructor in your class, so the compiler will not write any default constructor in your class,
so,
class Sup
{
public Sup(int i)
{
System.out.println("Super class");
}
}
public class Test2 extends Sup
{
public Test2(String str)
{
//super(); this will be inserted by compiler
System.out.println("Sub class");
}
public static void main(String[] args)
{
Test2 t2 = new Test2("22");
}
}
will give error since there is no default constructor in super class Sup.
-------------------------------------------------------------------------
You also can
test this,
public class Test2
{
public Test2(String str)
{
System.out.println("Sub class");
}
public static void main(String[] args)
{
Test2 t2 = new Test2();
}
}
this will also give you the same error.
[ December 13, 2005: Message edited by: Purujit Saha ]