Hello,
I am working on the problem of creating an abstract class Shape also with Package shape and then creating a subclasses Circle, Square and etc.
I belive, i don't have a complete understanding of an abstract. Anyways i keep getting an error: " Shape.Circle is not abstract and does not override abstract method perimeter() in Shape.Shape
I am not sure what that means. Does anyone know whats going on?

Here is my main, abstract class and subclass circle:

// Main
Package Shape;

import java.io.*;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException
    {

        BufferedReader stdin = new BufferedReader ( new InputStreamReader( System.in ) );       // Initiating Input Stream from the user

        String temp;
        double r;

        Circle c =  new Circle();           // Class Circle initiation
        Square s = new Square ();           // Class Circle initiation
        Rectangle rad = new Rectangle ();   // Class Circle initiation
        // User input reader
        System.out.println("Please enter the necessary component to calculate the area (radius, side etc.): ");
        temp = stdin.readLine();
        r = Double.parseDouble(temp);
        // Circle output
        System.out.println("The area of a Circle is " + c.area(r) + " squared units");
        System.out.println("The perimeter of a Circle is " + c.perimeter(r) + " units");

// Abstract class Shape
Package Shape;

abstract public class Shape
{
    public String color;

	public void setColor(String c) {
		color = c;
	}
	public String getColor() {
		return color;
	}
	abstract  double area();
    abstract  double perimeter();
}

// Subclass circle 
/
package Shape;


public class Circle extends Shape
{
    
    // Method area

     double area(double r)
    {
        return 3.14 * r * r;
    }

     double perimeter(double r)
    {
        return Math.abs(2 * 3.14 * r);
    }

}

Thank you in advance

Dear,

Abstract method must be impelemented into sub class with same name and signature (parameter datatype, order and return datatype).

abstract public class Shape {
    public String color;
	public void setColor(String c) {
		color = c;
	}
	public String getColor() {
		return color;
	}
	abstract  double area();
              abstract  double perimeter();
}

public class Circle extends Shape
{
    
    // overriden methods
     public  double area() { ... }
     public double permimeter() { ... }

      double area(double r)    
    {
        return 3.14 * r * r;
    }

     double perimeter(double r)
    {
        return Math.abs(2 * 3.14 * r);
    }

}

PS: Please keep in mind that the abstract method should have public access.

Thank you. I had it fixed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.