Kvarz

java inner classes test

Apr 18th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. //*******************************************************************
  2. // Java compiler created in PHP to quickly and safely test code.
  3. // NOTE: please read the 'More Info' tab to the right for shortcuts.
  4. //*******************************************************************
  5.  
  6. import java.lang.Math; // header stuff MUST go above the first class
  7.  
  8. // our main class becomes a file but the main method is still found
  9. public class HelloWorld
  10. {
  11.   public static void main(String[] args)
  12.   {
  13.     OtherClass myObject = new OtherClass("Hello World!");
  14.     System.out.print(myObject);
  15.     new OtherClass.InnerStatic().innerMethod();
  16.     System.out.print("" + OtherClass.InnerStatic.time);
  17.    
  18.     Dog dog = new Dog("hey");
  19.     dog.change(dog);
  20.     System.out.print(dog.name);
  21.   }
  22. }
  23. // this will become its own file too (and these can be in any order)
  24. public class OtherClass
  25. {
  26.   private String message;
  27.   private boolean answer = false;
  28.   public OtherClass(String input)
  29.   {
  30.     message = "Why, " + input + " Isn't this something?";
  31.   }
  32.   public String toString()
  33.   {
  34.     return message;
  35.   }
  36.  
  37.   public static class InnerStatic{
  38.     protected static String time = "time";
  39.     public InnerStatic(){
  40.     System.out.print("\nInnerStatic");
  41.     }
  42.    
  43.     public static void innerMethod(){
  44.         System.out.print("hey, I'm inner");
  45.       //this.toString();
  46.     };
  47.   }
  48.  
  49.  
  50.  }
  51.  
  52. public class Dog
  53. {
  54.   public String name;
  55.   public Dog(String name){
  56.     this.name = name;
  57.   }
  58.   public static void change(Dog dog){
  59.         dog.name = "something else";
  60.   }
  61. }
Add Comment
Please, Sign In to add comment