SHARE
TWEET

CircleClass - Java Example Class

a guest Jul 11th, 2013 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Java Example Class
  2.    Author: Jamie McGibbon
  3.    Date: July 11, 2013
  4.    http://TechnicalCafe.com
  5. */
  6.  
  7. public class CircleClass{
  8.  
  9. //attributes of the CircleClass class
  10. public final double PI = 3.14159;
  11. public double radius;
  12.  
  13. //constructor method (will have a parameter of type double for the radius)
  14. public CircleClass(double radius){
  15.  
  16.   //using the "this" reserveword, we can take the value from
  17.   //the "radius" variable that's in the constructor, and store
  18.   //it in the class variable called "radius", as "this" refers
  19.   //to the variable or attrivute that's in the class.
  20.   this.radius = radius;
  21.  
  22. }
  23.  
  24.  
  25.  
  26. //methods of the CircleClass class
  27.  
  28. public double findArea(){
  29.  
  30.   return PI*(radius*radius);
  31.  
  32.   //We can just use "radius" here, since we are refering to
  33.   //the class variable, called "radius", as the "radius" variable
  34.   //in the constructor method is not in the scope of this method,
  35.   //meaning we can't use it.
  36. }
  37.  
  38. public double findCircumference(){
  39.  
  40.   return 2*PI*radius;
  41.  
  42.   //Like with the previous method, we can just the "radius" here,
  43.   //since we want to use the class (instance) variable for "radius",
  44.   //and not the one used as a parameter for the constructor method,
  45.   //which is not in the scope of this method anyway.
  46. }
  47.  
  48.  
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top