Advertisement
smeacham

ConstructorDemo.java

Jan 26th, 2015
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.awt.Rectangle;
  2.  
  3. /**
  4.    This example demonstrates constructors.
  5. */
  6. public class ConstructorDemo
  7. {
  8.    public static void main(String[] args)
  9.    {
  10.       // Constructs and prints a rectangle
  11.       System.out.println(new Rectangle(5, 10, 20, 30));
  12.  
  13.       // Constructs a rectangle and saves it in a variable
  14.       Rectangle box = new Rectangle(5, 10, 20, 30);
  15.       System.out.print("box: ");
  16.       System.out.println(box);
  17.  
  18.       // The constructor with no arguments
  19.       box = new Rectangle();
  20.       System.out.print("box: ");
  21.       System.out.println(box);
  22.    }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement