Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to create a abstract shape class that has methods of setting and getting the width of the object. then i need to write a rectangle class that extends the shape class with methods of setting and getting the length as well as calculating and printing the area (width x length). im not sure on how to start this please help

What I have tried:

public class Shape {

   private double width = 100;
   private double height = 500;

    public Shape(int w, int h) {
        this.width = 5;
        this.setHeight(2);
    } 
    public Shape(double w, double h) {
    width = w;
    height = h;
    }
    public void setWidth(double width){
    	   this.width = width;
    	}

    	public double getWidth(){
    	   return width;
    	}
		public double getHeight() {
			return height;
		}
	public void setHeight(double height) {
			this.height = height;}
}
Posted
Updated 14-Nov-17 19:26pm
Comments
PIEBALDconsult 14-Nov-17 19:42pm    
That would be odd.
Member 13521455 14-Nov-17 21:40pm    
why?

1 solution

You have no inkling of what abstract class is, check this out: Abstract Methods and Classes[^]
 
Share this answer
 
Comments
CPallini 15-Nov-17 4:20am    
5.
Peter Leow 17-Nov-17 21:32pm    
Thank you, CPallini.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900