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

77 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+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions