1 Replies - 2728 Views - Last Post: 15 March 2012 - 02:14 PM Rate Topic: -----

#1 Solo610  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-October 11

Error: reason: actual and formal argument lists differ in length

Posted 15 March 2012 - 01:42 PM

In one of my labs we are creating the super class Circle with the child class Cylinder. When I try to compile the child class I get the error : reason: actual and formal argument lists differ in length for my last two methods inside child class. Am I correct to assume this has something to do with the constructor?
The first code is the parent class and the second is the child class.
public class Circle
{
	protected double radius;
	
	public Circle()
	{
		radius = 1.0; 
	}
	
	public Circle(double newRadius)
	{
		setRadius(newRadius);
	}
	
	public double getRadius()
	{
		return radius;
	}
	
	public void setRadius(double r)
	{
		radius = r;
	}
	
	public void calcArea(double radius)
	{
		double area = Math.PI*radius*radius;
	}
	
	public void calcPerimeter(double radius)
	{
		double perimeter = 2*Math.PI*radius;
	}
	
}


public class Cylinder extends Circle
{
	private double length;
	
	public Cylinder()
	{
		super();
		length = 1.0;
	}
	
	public Cylinder(double r, double l)
	{
		super(r);
		setLength(l);
	}
	
	public double getLength()
	{
		return length;
	}
	
	public void setLength(double newLength)
	{
		length = newLength;
	}
	
	public void calcArea(double r)  //error here
        {
		double area = calcPerimeter()*r + calcPerimeter()*length;
	}
	
	public void calcVolume(double r) //error here 
	{
		double volume = super.calcArea()*length;
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Error: reason: actual and formal argument lists differ in length

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2204
  • View blog
  • Posts: 5,236
  • Joined: 10-September 10

Re: Error: reason: actual and formal argument lists differ in length

Posted 15 March 2012 - 02:14 PM

Look at your test/driver class - whatever it is that is using the Cylinder class - and where it calls the last two methods of your Cylinder instance. Do the parameters in your driver match the arguments in your method signatures? If the answer isn't obvious, post your test/driver class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1