smeacham

OO Transformation - Step 3 - Combine creation with init

Sep 3rd, 2012
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         Account account1 = new Account(1, "Alice", "New York");
  4.         account1.view();
  5.        
  6.         Account account2 = new Account(2, "Zoe", "California");
  7.         account2.view();
  8.     }
  9. }
  10.  
  11. class Account {
  12.         int number;
  13.         String name;
  14.         String address;
  15.  
  16.     Account(int number, String name, String address) {
  17.         this.number = number;
  18.         this.name = name;
  19.         this.address = address;
  20.     }
  21.  
  22.     void view() {
  23.         System.out.println("Number: " + number);
  24.         System.out.println("Name: " + name);
  25.         System.out.println("Address: " + address);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment