Advertisement
Guest User

angestellter

a guest
Feb 11th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public class Angestellter{
  2. public int alter ;
  3. public String name ;
  4. public Angestellter( String name , int alter){
  5. this.name = name ;
  6. this.alter = alter ;
  7. }
  8.  
  9. public String toString() {
  10. return name + " ( " +alter+ " ) " ;
  11. }
  12. public static void main( String[] args){
  13. String s , abt ;
  14. Angestellter a = new Angestellter("Schmidt",30);
  15. Chef b = new Chef( "Meier" , 37," Buchhaltung " ) ;
  16.  
  17. s = a.name;
  18. a = b;
  19. abt = ((Chef) a).abteilung;
  20.  
  21. System.out.println(a.toString());
  22. System.out.println(b.toString());
  23. }
  24. }
  25.  
  26.  
  27.  
  28.  
  29. class Chef extends Angestellter{
  30. public String abteilung ;
  31. public Chef( String name , int alter, String abteilung){
  32. super( name , alter);
  33. this.abteilung = abteilung;
  34. }
  35.  
  36. public String toString(){
  37. String s = super . toString ( ) ;
  38. return s + " leitet " + abteilung ;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement