SHARE
TWEET

MainClass - Java Sample Class

a guest Jul 11th, 2013 60 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 MainClass{
  8.  
  9.   //"main" method of the "MainClass" class, which will allow us to
  10.   //run the program that we have written.
  11.  
  12.   public static void main(String [] args){
  13.  
  14.     //Instantiate a new object of the "CircleClass" class, which
  15.     //we have called "myCircle", passing in a radius value of "5"
  16.     //to the "CircleClass" class constructor method.
  17.    
  18.     CircleClass myCircle = new CircleClass(5);
  19.    
  20.     //Now that we have instanted an object of the "CircleClass" class,
  21.     //we can call the methods of the class that we wrote, in order to
  22.     //find out the area and circumference of a circle with a radius
  23.     //of 5 units.
  24.    
  25.     //Calling the findArea() method, and storing the result in a variable
  26.    
  27.      double area = myCircle.findArea();
  28.      
  29.      //Calling the findCircumference() method of the "CircleClass" class
  30.      
  31.      double circumference = myCircle.findCircumference();
  32.      
  33.      //Print the results
  34.      
  35.      System.out.println("Area: " + area);
  36.      System.out.println("Circumference: " + circumference);
  37.      
  38.     //(We could also print the results directly from these method calls by
  39.     //putting the method call in a "System.out.println()" statement.
  40.      
  41.     //Additionally, we could use the "Scanner" class to take input from the
  42.     //user, providing a parameter for the constructor that way, rather than
  43.     //having to edit the class each time you want to run the program.  
  44.  
  45.   }
  46.  
  47. }
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