COP 3502 Lecture Notes - Lecture 27: Member Variable

65 views3 pages

Document Summary

Objects: an object has both a state and behavior, the state defines the object, and the behavior defines what the object does. //define the circle class with two constructors class simplecircle { double radius; //member variable - defines the state of the object. Cop3502 page 1 state of the object int borderwidth; public simplecircle (double radius) this. radius = radius; borderwidth = 1; //the only method in double that doesn"t have a return type. // a constructors only job is to make the object. //anything you need to know the moment you create an object is a parameter. //this method is what gets called whenever you want to make a circle object public simplecircle (double radius, int borderwidth){ this. radius = radius; this. borderwidth = borderwidth; //this. radius refers to the member variable (above) - the state. //radius refers to the parameter of this method, which got passed in public double getarea(){ return radius * radius * math. pi;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents