












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Java Programming: From Problem Analysis to Program Design, Second Edition 1
ย Classes - introduction. ย Protection and modifiers ย Class implementation. ย Operations on classes. ย Constructors and finalizers. ย The method toString. ย Abstract data types (ADT).
Java Programming: From Problem Analysis to Program Design, Second Edition 2
ย class: A reserved word; a collection of a fixed number of components. ย Components: Members of a class. ย Members are accessed by name. ย Class categories/modifiers:
Java Programming: From Problem Analysis to Program Design, Second Edition 3
ย Private: Members of class are not accessible outside class. ย Public: Members of class are accessible outside class. ย Class members: Can be methods or variables. ย Variable members are declared like any other variables.
Java Programming: From Problem Analysis to Program Design, Second Edition 4
The general syntax for defining a class is:
ย If a member of a class is a named constant, you declare it just like any other named constant. ย If a member of a class is a variable, you declare it just like any other variable. ย If a member of a class is a method, you define it just like any other method. ย If a member of a class is a method, it can (directly) access any member of the classโdata members and methods. Therefore, when you write the definition of a method (of the class), you can directly access any data member of the class (without passing it as a parameter).
Java Programming: From Problem Analysis to Program Design, Second Edition 7
class Clock: Constructors ย Default constructor is public Clock().
Constructor with parameters: ย public Clock(int hours, int minutes,int seconds)
Java Programming: From Problem Analysis to Program Design, Second Edition 8
Java Programming: From Problem Analysis to Program Design, Second Edition 9
Variable Declaration and Object Instantiation
The general syntax for using the operator new is: new className() OR new className(argument1, argument2, ..., argumentN)
Clock myClock; Clock yourClock; myClock = new Clock(); yourClock = new Clock(9, 35, 15);
Java Programming: From Problem Analysis to Program Design, Second Edition 10
Variable Declaration and Object Instantiation
Java Programming: From Problem Analysis to Program Design, Second Edition 13
ย Shallow copying: Two or more reference variables of the same type point to the same object. ย Deep copying: Each reference variable refers to its own object.
Java Programming: From Problem Analysis to Program Design, Second Edition 14
ย Executes when an object is instantiated. ย Initialized using an existing object. ย Syntax: public ClassName(ClassName otherObject)
Java Programming: From Problem Analysis to Program Design, Second Edition 15
Java Programming: From Problem Analysis to Program Design, Second Edition 16
ย Public value-returning method. ย Takes no parameters. ย Returns address of a String object. ย Output using print, println, printf methods. ย Default definition creates String with name of objectโs class name followed by hash code of object.
Java Programming: From Problem Analysis to Program Design, Second Edition 19
void setX(int a) { x = a; } public String toString() { return("x = " + x + ", y = " + y
Illustrate illusObject = new Illustrate(); Illustrate.incrementY(); Illustrate.count++;
Java Programming: From Problem Analysis to Program Design, Second Edition 20
Illustrate illusObject1 = new Illustrate(3); Illustrate illusObject2 = new Illustrate(5);
Java Programming: From Problem Analysis to Program Design, Second Edition 21
Illustrate.incrementY(); Illustrate.count++;
Java Programming: From Problem Analysis to Program Design, Second Edition 22
ย Automatically execute when class object goes out of scope. ย Have no parameters. ย Only one finalizer per class. ย Name of finalizer: finalize.
Java Programming: From Problem Analysis to Program Design, Second Edition 25
package jpfpatpd.ch08.clockPackage; public class Clock { //put instance variables and methods, //as before, here }
import jpfpatpd.ch08.clockPackage.Clock;
Java Programming: From Problem Analysis to Program Design, Second Edition 26
ย Refers to instance variables and methods of a class. ย Used to implement cascaded method calls.
Java Programming: From Problem Analysis to Program Design, Second Edition 27
ย Defined within other classes. ย Can be either a complete class definition or an anonymous inner class definition. ย Used to handle events.
Java Programming: From Problem Analysis to Program Design, Second Edition 28
A data type that specifies the logical properties without the implementation details.
Java Programming: From Problem Analysis to Program Design, Second Edition 31
Components: ย Cash register ย Dispenser ย Machine
Java Programming: From Problem Analysis to Program Design, Second Edition 32
Java Programming: From Problem Analysis to Program Design, Second Edition 33
Java Programming: From Problem Analysis to Program Design, Second Edition 34
Java Programming: From Problem Analysis to Program Design, Second Edition 37
Java Programming: From Problem Analysis to Program Design, Second Edition 38
ย Creating classes ย Members of a class: ย private ย protected ย public ย static ย Implementing classes ย Various operations on classes ย Constructors ย Finalizers ย Method toString ย Abstract data types
Java Programming: From Problem Analysis to Program Design, Second Edition 39