[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 Representing Numbers in Java. On to Object Basics (2).
Held: Wednesday, 14 September 2005
Summary:
Today we begin the study of classes, the primary building
blocks of Java programs. As you've seen, classes can provide the
main method. However, most classes serve instead as
templates for creating new objects.
Related Pages:
Overview:
package yourname.naturalgruoping;
import ClassWhoseNameYouDontWantToTypeInFull;
/**
* A helpful introductory comment that describes the class.
*/
public class ClassName
{
// Field declarations
// Constructors
// Methods
} // class ClassName
String name;
anywherein the class; variables are available only in the method they are declared in.
this.
public String getName()
{
return this.name;
} // getName()
public void setName(String newName)
{
this.name = newName;
} // setName(String)
protection ClassName(parameters)
{
body
} // ClassName(parameters)
name, that we want to initialize with a string whenever we create an object, we might write the following:
public NamedThing(String _name)
{
this.name = _name;
} // NamedThing(String)
// Fields
int counter;
// Constructors
public Counter()
{
this.counter = 0;
} // Counter()
Back to Representing Numbers in Java. On to Object Basics (2).
[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:20 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.12.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby