AbstractClasses - CIS3023 Programming Fundamentals for CIS...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Abstract Classes Course Lecture Slides 7 June 2010 “None of the abstract concepts comes closer to fulfilled utopia than that of eternal peace.” --Theodor W. Adorno Example Drawing Application Create different shapes: circle, rectangle, … So now we can instantiate a Geom etricObject as follows: Geom etricObject g = new Geom etricObject(); But does it m ake sense ? Solution – Abstract Classes! Do not allow instantiation of GeometricObject class How? 66 Declare it as abstract as follows: public abstract class GeometricObject { … } Abstract Class Want to add methods to compute area and perimeter of any GeometricObject 88 Abstract Class Added methods to compute area and perimeter for any GeometricObject! 99 public abstract class GeometricObject { private String color = "white"; private boolean filled; protected GeometricObject() { filled = false; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public boolean isFilled() { return filled; } public void setFilled(boolean filled) { this.filled = filled; } public String toString() { return "color: " + color + " and filled: " + filled; } } 1010 public class Circle extends GeometricObject { private double radius; public Circle() { radius = 1.0; } public Circle(double radius) { this.radius = radius; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } public double getArea() { return radius * radius * Math.PI; } public double getPerimeter() { return 2 * radius * Math.PI; } } 1111 public class Rectangle extends GeometricObject { private double width; private double height; public Rectangle() { width = 1.0; height = 1.0; } public Rectangle(double width, double height) { this.width = width; this.height = height; } public double getWidth() { return width; } public void setWidth(double w){ width = w; } public double getHeight() {...
View Full Document

This note was uploaded on 05/27/2011 for the course CIS 3023 taught by Professor Dobbins during the Summer '08 term at University of Florida.

Page1 / 25

AbstractClasses - CIS3023 Programming Fundamentals for CIS...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online