error Cal(int, int) in Cal cannot be applied to ()


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: error Cal(int, int) in Cal cannot be applied to ()

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Posts
    9

    error Cal(int, int) in Cal cannot be applied to ()

    Hi I get this error Cal(int, int) in Cal cannot be applied to ()
    No idea whats going on.



    class Cal{
    private int base;
    private int height;
    private int total;

    public Cal(int b,int h){
    base=b;
    height=h;
    }
    public void setHeight(int num){
    height=num;
    }
    public void setBase(int num){
    base=num;
    }
    public void getTotal(){
    System.out.println("Area of a Rectangle is " +base*height);
    }
    }

    //====================================================
    class Cal2 extends Cal{
    private int radius;
    private int total2;


    Cal2(int r){
    radius = r;
    }
    public void setRadius(int num){
    radius=num;
    }
    public void getTotal2(){
    System.out.println("Area of a circle is " +3.14*radius*radius);
    }
    }

    //=================================================
    public class Inheritance4{
    public static void main (String[] args){

    Cal areaRectangle =new Cal(3,4);
    Cal2 areaCircle =new Cal2(4);
    areaRectangle.getTotal();

    }
    }

  2. #2
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    quiet easy:
    when you activate the constuctor of Cal2, it implicitly tries to call the Constructor of Cal. Since you didn't define it otherwise, that's the default constructor with no parameters, and this one doesn't exist.
    you will have to either
    provide a default constructor for Cal like
    Code:
    public Cal(){}
    or write a constructor for Cal2 like this:
    Code:
    Cal2(int r, int b,int h){
    super(b,h);
    radius = r;
    }

  3. #3
    Join Date
    Feb 2006
    Posts
    9
    Thanks alot that worked

Similar Threads

  1. KeyListener not responding
    By lordanki in forum Java
    Replies: 3
    Last Post: 04-04-2006, 11:13 AM
  2. queues how to print it
    By xsouldeath in forum Java
    Replies: 0
    Last Post: 12-10-2005, 11:56 PM
  3. Input string was not in a correct format
    By mdengler in forum ASP.NET
    Replies: 0
    Last Post: 11-26-2002, 03:32 PM
  4. Producer Consumer Thread
    By Chirag in forum Java
    Replies: 6
    Last Post: 04-10-2002, 06:22 AM
  5. INSERT for multiple tables with IDENTITY
    By Kay in forum Database
    Replies: 1
    Last Post: 07-04-2001, 06:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center