therrontelford

What's Inside

Feb 2nd, 2020
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1.  
  2. class Monster
  3. {
  4.     private String myName;
  5.  
  6.     public Monster()
  7.     {
  8.         //myName = "Monster";    //uncomment and recompile and run
  9.     }
  10.  
  11.     public Monster( String name )
  12.     {
  13.         myName = name;
  14.     }
  15.  
  16.     public String toString( )
  17.     {
  18.         return myName;
  19.     }
  20. }
  21.  
  22. class Witch extends Monster
  23. {
  24.    public Witch( )  //GoodWitch will not compile without this constructor
  25.    {
  26.     //automatically calls super()
  27.    }  
  28.  
  29.    public Witch( String name )
  30.    {
  31.  
  32.    }
  33. }
  34.  
  35. class GoodWitch extends Witch
  36. {
  37.    //what do we need here??
  38.    // I inserted
  39.     //public GoodWitch(){
  40.        
  41.     //}
  42.    
  43.    public GoodWitch( String name )
  44.    {
  45.       //automatically calls super()
  46.    }
  47. }
  48.  
  49. public class WhatsOnTheInside
  50. {
  51.     public static void main ( String[] args )
  52.     {
  53.         GoodWitch bad = new GoodWitch();        //why does this not compile
  54.         System.out.println(bad);
  55.        
  56.         GoodWitch witch = new GoodWitch("Harriet");
  57.         System.out.println(witch);
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment