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 MainClass{
- //"main" method of the "MainClass" class, which will allow us to
- //run the program that we have written.
- public static void main(String [] args){
- //Instantiate a new object of the "CircleClass" class, which
- //we have called "myCircle", passing in a radius value of "5"
- //to the "CircleClass" class constructor method.
- CircleClass myCircle = new CircleClass(5);
- //Now that we have instanted an object of the "CircleClass" class,
- //we can call the methods of the class that we wrote, in order to
- //find out the area and circumference of a circle with a radius
- //of 5 units.
- //Calling the findArea() method, and storing the result in a variable
- double area = myCircle.findArea();
- //Calling the findCircumference() method of the "CircleClass" class
- double circumference = myCircle.findCircumference();
- //Print the results
- System.out.println("Area: " + area);
- System.out.println("Circumference: " + circumference);
- //(We could also print the results directly from these method calls by
- //putting the method call in a "System.out.println()" statement.
- //Additionally, we could use the "Scanner" class to take input from the
- //user, providing a parameter for the constructor that way, rather than
- //having to edit the class each time you want to run the program.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement