Practice of Programming using Java
Lecture 5 June 22, 2006. 6-8 pm

Rushikesh K Joshi

Department of Computer Science and Engineering

Indian Institute of Technology Bombay

Today's new class: Class String

String comes from java.lang

String (char []input)

String (char []input, from, howmany)

String (String another)

char charAt (int pos)

concact (String another)

endsWith (String suffix)

indexOf (char c)	indexOf (char c, int from)

indexOf (String another)	indexOf (String another, int from)

valueOf (int i)	other value of functions

Replace occurances of characters, Trimming whitespaces etc.

Interfaces

Specify externally observable member functions

Only the prototype declarations are specified and implementation is not specified and left for implementor class/classes.

interface Collection {

public Object fetch();

oublic Object add(Object o);

}

class Stack implements Collection {

...

public Object fetch () {..}

public Object add (Object o) {...}

}

Inheritance

Mechanism for

Pure Extension

C1={f,g,h}

C2=C1+{p,q}

Variant Behavior

C1={f,g,h}

C2=C1 with f’ to be treated as f, rest of c1 as it is

Polymorphism

Use instances of C2 where instances of C1 are required

Pure Extension

Is Extension of

Generalization

Specialization

Variant Behavior

Is a variation of

Generalization

Specialization

Essence of Polymorphism

inheritance

inheritance

inheritance

Any code that uses the generalization

Can work with any specialization

Generalization

3 Specializations

An Example of Inheritance Hierarchy of objects in a graphical drawing tool

shape

Circle

Rectangle

Triangle

Principles of Object Orientation

RKJPC

2006-06-22T22:19:52