Wednesday, October 26, 2011

WALKTHROUGH:TNB Java Tut 49 -"Inheritance" [VIDEO] [SOURCE CODE]

This is a full walk-through of Java Tutorial 49-"Inheritance" by TheNewBoston.This walk-through includes:
  • Embedded Video Tutorial
  • Alternative explanation & source code
  • Visual Breakdown of the code
In this walk-through you will learn about using the "toString" method, a very useful method used to give any object a default string representation.





Super Classes:Super classes are alot like super stars(celebrity's)that influence us.You might never be Kanye west, but from listening/watching  to him you can inherit some of his talents and beliefs(methods). Think of "super classes" as "super stars" that you're regular classes look up to.
 public class superStarKanyeWest{  
   public void rap(){  
   System.out.println("yo yo yo");  
 }  
   public void makeBeats(){  
   System.out.println("BOOM BOOM shimmy BOOM BOOM");  
 }  
   public void personalPhilosophy(){  
   System.out.println("Shoot for the stars so if you fall you land on a cloud.");  
 } 
   public void politicalBeliefs(){  
   System.out.println("George Bush does not care about black people.");  
 }  
 }  
(Example of a "Super Class")




Joe Nobody is just a normal teenager, he himself has no super powers, but hes a fan of Kanye's and aspires to one day become a world famous rapper.Because Kanye inspires Joe we could say Joe is a extension of what Kanye represents because we are all extensions of the people who inspire us.    
OVERIDE:In the java world because Joe looks up to (extends) Kanye by default he inherits all of Kanyes public methods, but Joe can also overwrite individual methods he disagrees with Kanye about, such as political beliefs.
 
Even thought Joe inherited alot of his talents and qualitys(methods) from studying Kanye, Joe is still unique and can have talents(methods) of his own Kanye doesn't such as knowing how to play the guitar.
 public class joeNobody extends superStarKanyeWest{  
  int age=18;  
     public void playGuitar(){  
    System.out.println("I can play guitar");  
  }  
     public void politicalBeliefs(){  
   System.out.println("All politicians are evil crooks and talking politics just gets people pissed off so I just stay out of that stuff.");  
     }   
 }  
(joeNobody Class)


Bobby is Joes little brother, bobby looks up to Joe.Bobby doesn't even know who Kanye is yet,but Because some of Joes quality's are inherited from Kanye,Bobby inherits the the quality's Joe picked up from Kanye as well as all of Joes unique quality's. 
Because Joe overode Kanyes political beliefs Bobby will share Joes politicalBeliefs.
playBasketball() is a method unique to bobby
 public class bobbyNobody extends joeNobody{  
  int age=15;  
      public void playBasketballGood(){  
    System.out.println("I can shoot 10 for 10 from the free throw line.");  
  }  
 }  
(bobbyNobody Class)

End of Tutorial

No comments:

Post a Comment

 
;