[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Labs] [Assignments] [Examples] [Bailey Docs] [SamR Docs] [Tutorial] [API]
Held: Monday, January 26, 1998
new operation in conjunction with
constructors.
// The current teacher I have to deal with. Teacher current_teacher; ... // Oh boy, time to work in 152. current_teacher = samr; ... // Time for the cool languages reading group. current_teacher = stone; ...
samr and stone
have already been make to refer to particular objects.
if or conditional statement is one of the
simplest control structures.
if statement.
if (test) statement executes the
statement only when the test holds.
if (test) statement else
statement selects between the two statements. It executes
the first if the test evaluates to true and the second if it
evalutes to false.
if
statements.
Complex class, we'll have three constructors:
/**
* Initialize to 0.0 + 0.0i
*/
public Complex()
{
real_part = 0.0;
imaginary_part = 0.0;
} // Complex()
/**
* Initialize to x + y*i
*/
public Complex(double x,double y)
{
real_part = x;
imaginary_part = y;
} // Complex(double,double)
/**
* Initialize to x + 0.0i
*/
public Complex(double x)
{
real_part = x;
imaginary_part = 0.0;
} // Complex(double)
this.
For example, we might redefine the simplest constructor as
/**
* Initialize to 0 + 0i.
*/
public Complex()
{
this(0.0, 0.0);
} // Complex()
On to Lab: Building Classes
Back to Describing Classes
Outlines:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Current position in syllabus
[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Labs] [Assignments] [Examples] [Bailey Docs] [SamR Docs] [Tutorial] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/98S/home/rebelsky/public_html/Courses/CS152/98S/Outlines/outline.05.html
Source text last modified Tue Jan 12 11:52:17 1999.
This page generated on Mon Jan 25 09:48:45 1999 by SiteWeaver. Validate this page.
Contact our webmaster at rebelsky@math.grin.edu