Week11Chap7-III

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

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

View Full Document Right Arrow Icon
Janaka Balasooriya CSE 110, Arizona State University Chapter 8 Establishing Relationship Among Classes Introduction to Inheritance
Background image of page 1

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

View Full DocumentRight Arrow Icon
Janaka Balasooriya CSE 110, Arizona State University Arrays : Practice Question Solutions
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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()
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
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 Right Arrow Icon
Ask a homework question - tutors are online