Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1.  
  2. public class Main
  3. {
  4.     public static void main(String[] args)
  5.     {
  6.         System.out.println("Here is our main method in one class.");
  7.         // Now lets print a statement from a different class.
  8.         // To do so, we create a new instance of that class.
  9.         // Use them like variables, by declaring them, and then using the new
  10.         // keyword.
  11.         Piano p = new Piano();
  12.  
  13.         // So instead of having a variable named int, or boolean, I just have
  14.         // one named Piano!
  15.         // now lets use a method inside the Piano class, from our Main class.
  16.         // To "look into" the Piano class, from outside of it, we use the "dot"
  17.         // (.) operator.
  18.  
  19.         p.play();
  20.     }
  21.  
  22. }
  23.  
  24.  
  25. /////////////////////////PIANO CLASS IN A SEPERATE FILE NAMED Piano.java/////////////////////////
  26.  
  27. public class Piano
  28. {
  29.  
  30.     public void play()
  31.     {
  32.         System.out.println("Soft Music fills the air...");
  33.     }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement