05JavaOOP - CMSC 132: Object-Oriented Programming II Java...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park this Reference Description Reserved keyword Refers to object through which method was invoked Allows object to refer to itself Use to refer to instance variables of object this Reference Example class Node { value val1 ; value val2 ; void foo(value val2 ) { = val1 ; // same as this.val1 (implicit this) = val2 ; // parameter to method = this . val2 ; // instance variable for object bar( this ); // passes reference to object } } Also used in constructors to invoke another constructor in the same class. Inheritance Definition Relationship between classes when state and behavior of one class is a subset of another class Terminology Superclass / parent More general class Subclass More specialized class Forms a class hierarchy Helps promote code reuse super Reference Description Reserved keyword Refers to superclass Allows object to refer to methods / variables in superclass Examples super.x // accesses variable x in superclass super() // invokes constructor in superclass super.foo() // invokes method foo() in superclass References & Aliases Reference A way to get to an object, not the object itself All variables in Java are references to objects Alias Multiple references to same object x == y operator tests for alias x .equals( y ) tests contents of object (potentially) Object z Reference x Reference y Implementing Equals Approach we want to use (assuming class A ) public boolean equals(Object obj) { if (obj == this) return true; if (!(obj instanceof A )) return false; A a = (A)obj; /* Specific comparison based on A fields appears here */ } Example: See equalsMethod package Constructor Description Method invoked when object is instantiated Helps initialize object Method with same name as class w/o return type...
View Full Document

Page1 / 30

05JavaOOP - CMSC 132: Object-Oriented Programming II Java...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online