Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main
- {
- public static void main(String[] args)
- {
- System.out.println("Here is our main method in one class.");
- // Now lets print a statement from a different class.
- // To do so, we create a new instance of that class.
- // Use them like variables, by declaring them, and then using the new
- // keyword.
- Piano p = new Piano();
- // So instead of having a variable named int, or boolean, I just have
- // one named Piano!
- // now lets use a method inside the Piano class, from our Main class.
- // To "look into" the Piano class, from outside of it, we use the "dot"
- // (.) operator.
- p.play();
- }
- }
- /////////////////////////PIANO CLASS IN A SEPERATE FILE NAMED Piano.java/////////////////////////
- public class Piano
- {
- public void play()
- {
- System.out.println("Soft Music fills the air...");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement