Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Java Example Class
- Author: Jamie McGibbon
- Date: July 11, 2013
- http://TechnicalCafe.com
- */
- public class CircleClass{
- //attributes of the CircleClass class
- public final double PI = 3.14159;
- public double radius;
- //constructor method (will have a parameter of type double for the radius)
- public CircleClass(double radius){
- //using the "this" reserveword, we can take the value from
- //the "radius" variable that's in the constructor, and store
- //it in the class variable called "radius", as "this" refers
- //to the variable or attrivute that's in the class.
- this.radius = radius;
- }
- //methods of the CircleClass class
- public double findArea(){
- return PI*(radius*radius);
- //We can just use "radius" here, since we are refering to
- //the class variable, called "radius", as the "radius" variable
- //in the constructor method is not in the scope of this method,
- //meaning we can't use it.
- }
- public double findCircumference(){
- return 2*PI*radius;
- //Like with the previous method, we can just the "radius" here,
- //since we want to use the class (instance) variable for "radius",
- //and not the one used as a parameter for the constructor method,
- //which is not in the scope of this method anyway.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement