Lecture 5

homeContentsIndexPrevNext

Lecture Topic:

What's class point?

-- it has two data members that keeps its
location, and some functions that tell its attributes(location, magnitude...).
class Point { 
  
 

What's class ray?

-- It is a line between two points, so it
has two points and function which tells if it intersects with another ray.
class Ray { Point p1, p2; point intersect(Ray r); } Point Ray::intersect(Ray
r) { 
  
 

NULL

-- null value can be used to detect whether
an object has an viable instance.
if (user.object != NULL)
system.out.println("Object exist"); 

Operators

"==" means equal / instance of
Syntax: 
  
Example: 
  

Casting

-- is data type conversion. In class casting,
you should only winden a class by casting it to a superclass. public
class simpleDraw extends Applet { Vecter drawnShapes; void paint(Graphics
g) { 
  
}
 

Extending a class

1>. If this class is a subclass of another
class, use extends to indicate the superclass of this class: Syntax:
class myClassName extends mySuperClassName { ... } Example:
class Target extends Shape { 
void draw(graphics g ) { g.setcolor(this.color);
fill_circle(g, Pi, Shape.radius); } 
} 2>.
If this class implements a specific interface, use implements to refer to
that interface: Syntax: class MyRunnableClassName implements Runnable
{ ... }
 

Sample Quiz


 
1. What does class extension do?
 
  a. adding more classes.
 
  b. define more features to a existing class.
 
  c. new class in java can be extensions of any single existing class.
 
 
 


homeContentsIndexPrevNext

UBLOGOLast Update: 10/07/96
Copyright ©1996 - Douglas Lyon
Lyon@cse.bridgeport.edu