Week11Chap7-III

# Week11Chap7-III - + void calcPerimeter() Janaka Balasooriya...

This preview shows pages 1–6. Sign up to view the full content.

Janaka Balasooriya CSE 110, Arizona State University Chapter 8 Establishing Relationship Among Classes Introduction to Inheritance

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

View Full Document
Janaka Balasooriya CSE 110, Arizona State University Arrays : Practice Question Solutions
Janaka Balasooriya CSE 110, Arizona State University Some Objects Belongs to The Same Family Car Truck Rectangle Square Vehicle Shape • Objects belong to the same family can share attributes and methods • Individual objects in the family can have their own attributes and methods

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

View Full Document
Janaka Balasooriya CSE 110, Arizona State University public class shape { protected int area; protected int perimeter; public String toString() { return "area = " + area + " perimeter = " + perimeter; } } Rectangle and Shape Classes shape rectangle - length : int - width : int + String toString() # area : int # perimeter : int + void calcArea()

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: + void calcPerimeter() Janaka Balasooriya CSE 110, Arizona State University // rectangle class is inherited from the shape class public class rectangle extends shape { private int lenght; private int width; public rectangle(int l , int w) { lenght = l; width = w; } public void calcArea() { // area is inherited from the shape area = lenght * width; } public void calcPerimeter() { // perimeter is inherited from the shape perimeter = 2 * (lenght + width); } public static void main(String args) { int len = 10, wid = 8; rectangle r = new rectangle(len, wid); r.calcArea(); r.calcPerimeter(); System.out.println(r); } } Rectangle and Shape Classes Janaka Balasooriya CSE 110, Arizona State University Homework Activity Complete the in class activity...
View Full Document

## This note was uploaded on 12/08/2010 for the course CSE 110 taught by Professor Kim during the Spring '08 term at ASU.

### Page1 / 6

Week11Chap7-III - + void calcPerimeter() Janaka Balasooriya...

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

View Full Document
Ask a homework question - tutors are online