[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
Back to Object Basics (1). On to Conditionals (1).
Held: Friday, 16 September 2005
Summary: Today we continue our basic study of classes, focusing on the design of a particular class.
Related Pages:
Assignments
Notes:
Overview:
protection type name;
protection NameOfClass(parameters)
{
} // NameOfClass(types-of-parameters)
public).
void when a method doesn't return anything.
Vector2D class.
main method. You can
think of the main method as a combination of the script
and directory of a play. This method creates the objects that form
the initial actorsof the play that is your program. It then tells them what to do.
toString.
equals, which you use to determine whether one object is "naturally" the same as another object.
equals method is
public boolean equals(Object other)
Vec2D ovec = (Vec2D) other;
instanceof operation
if (other instanceof Vec2D) {
Vec2D ovec = (Vec2D) other;
...
}
else {
return false;
}
compareTo method is a more general form of comparison.
public boolean compareTo(Object other)
compareTo method, you should indicate that your template class implements Comparable, as in
public class ClassName
implements Comparable
{
// ...
} // class ClassName
giving upin a few days.
clone method makes another copy of the current object.
clone method, you should indicate that your mold class implements Cloneable.
public class ClassName
implements Cloneable
{
// ...
} // class ClassName
clone and compareTo, you must write
public class ClassName
implements Cloneable, Comparable
{
// ...
} // class ClassName
clone is
public Object clone()
hashCode method returns some integer that represents this object.
hashCode method in the second half of the semester, but I'd like you to start including it in your classes now.
static.
static long created = 0;
...
public ClassName(parameters)
{
created = created + 1;
...
}
...
/**
* Determine how many objects have been created by this class
* in this session.
*/
public static int productivity()
{
return created;
} // int productivity()
/**
* Reset the count of objects created by the class.
*/
public static int reset()
{
created = 0;
} // reset()
Back to Object Basics (1). On to Conditionals (1).
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Tue Dec 6 09:47:21 2005.
The source to the document was last modified on Thu Aug 25 16:15:07 2005.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2005F/Outlines/outline.13.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby