letsdoitjava

Inheritance Practice

Jul 18th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. package Artist;
  2.  
  3. public class Country {
  4.     private String artist = "Garth Brooks";
  5.  
  6.        public String setArtist() {
  7.         return artist;
  8.        }
  9.  
  10.        void does(){
  11.         System.out.println("Plays Country Music" + " he is 57 years old");
  12.        }
  13.     }
  14. =======================================================================================================================================
  15. package Artist;
  16.  
  17. public class GarthBrooks extends Country{
  18.         public static void main(String args[]){
  19.            
  20.         Country obj = new Country();
  21.        
  22.         /* Note: using public setter method
  23.          * to access the private members of parent class
  24.          */
  25.         System.out.println(obj.setArtist());
  26.  
  27.         obj.does();
  28.        }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment