CSC207H5 Lecture Notes - Lecture 2: Master Sergeant, Multiple Inheritance

75 views16 pages
School
Course
Professor

Document Summary

Class members can be declared , public, protected, private, final or static or the members can be declared as abstract. Syntax for abstract class abstract class classname { abstract type methodname1(); // no method body. Type methodname2() { // normal method with body. Example : shape class: recall the circle and triangle classes from the activities. Now let"s add an abstract class called shape creating the following class hierarchy. The circle class public class circle extends shape { public double area() { return math. pi * radius * radius; public double perimeter(){ return 2 * math. pi * radius: remember : The methods area()and perimeter()must be defined in the circle subclass, otherwise circle objects cannot be created! The triangle class public class triangle extends shape { public double area() { return ; public double perimeter(){ return side1 + side2 + side3: remember : The methods area()and perimeter()must be defined in the triangle subclass, otherwise triangle objects cannot be created!

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions