Homework 01 § See description on Canvas. It is all about inheritance, abstract (class and method), and polymorphism. § Due date: You have a week to accommodate to your needs, but you do not need a full week to complete it. No extensions
Polymorphism § A polymorphic reference is a reference variable that can refer to different types of objects at different points in time. § Polymorphic references are resolved at run-time, not during compilation.
Circle public class Circle extends Shape { public Circle (double s) { super(s); System.out.println("A Circle is born"); } public double area() { return Math.PI * size * size;} }
Main public class Main { public static void main(String[] a) { Shape shape1, shape2, shape3; shape1 = new Triangle(5); System.out.println(shape1.area()); shape2 = new Square(5); System.out.println(shape2.area()); shape3 = new Circle(5); System.out.println(shape3.area()); } }
Ph.D. [email protected] Fall 2021 Copyright. These slides can only be used as study material for the class CSE205 at Arizona State University. They cannot be distributed or used for another purpose.