








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!









How to create your own classes
Encapsulation (wrapping together)
Attributes (data)
Methods (behavior)
Information hiding
Class
Instantiation
that represents an arbitrary circle in theplane. What does it take to describe a circle?
A pointA radius What constitutes a point?
An x – coordinateA y – coordinate
So three pieces of information are needed for a
circle. It can be represented by three doublenumbers which represent the x-coordinate,the y-coordinate and the radius. Our classwill need these three data items.
web page for the class. We will develop thisclass to the point that we can:
declare a circle;
assign or set the values of a circle;
show information about the circle;
Throughout the development we need to pay
attention to encapsulation and protection. Forexample, would you ever want a circle with anegative radius?
and we need to know whether or not twocircles (already established) intersect eachother. We will set up a boolean valued method that
will let one object call the method and test itwith another object.
will have names and represent attributesassociated with an object in the class. Properties can also be used to retrieve data
from an object or set data in an object.
return-type property-name
{
get{
code to get information
} set{
code to set information
} }
portion, you will see some similarities with theSetCircle method. When a property is used to set a value, as in
C1.Radius = 3.2; The value of the expression on the right of the
= is computed and is represented by thereserved word
value
in the property definition.
adding new lines of code in Main( )
Write a property that will set and get the x –coordinate.
Write a property that will set and get the y –coordinate.
Write a property that will return thecircumference of a circle.