What is the error in this Program

Just see the following program:

class A
{
   int a;
         A(int i)
           {
                a=i;
                System.out.println("This is constuctor A");
                System.out.println("A Value is "+a);
          }
}
class B extends A
{
        void b1()
         {
             System.out.println("This is class B");
         }
}
class C
{
   public static void main(String args[])
    {
       A a  = new A(5);
       B ob = new B();
       ob.b1();
   }
}

What is the wrong the above program?
When I'm compailng the program display errors.
The error is in:
  " symbol  :  can not resolve symbol
    location : Constructor A() "

--------------------------------------------------

You should provide a default constructor in A.

--------------------------------------------------

You need to specify a no-arg super class constructor in your superclass.
You are getting the error in the statement         B ob = new B();
The above statement will call super() since you have not supplied a constructor in class B.

--------------------------------------------------

In this program class A is the super class to B.
When creating object of class B with no argument which is going to invoke super class default constructor which is A( ).
In java default constructor will be supplied but when you have argument constructor  A(int i)  then it won't supply any default constructor A( ).
In class A you have to write A( ) and then compile it.

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.