Created
September 23, 2016 12:56
-
-
Save tipochka/36c6e36a22d373b701b3c61b06e2fd8b to your computer and use it in GitHub Desktop.
Блинов. Глава 4. Вариант А. 10 (*). Создать объект класса Щенок, используя классы Животное, Собака. Методы: вывести на консоль имя, подать голос, прыгать, бегать, кусать.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package oop.lesson2.homework.puppy; | |
public class Animal { | |
protected String name; | |
public Animal(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package oop.lesson2.homework.puppy; | |
public class Dog extends Animal { | |
public Dog(String name) { | |
super(name); | |
} | |
public String votesCast(){ | |
return "Gav"; | |
} | |
public String jump() { | |
return "Jump"; | |
} | |
public String run() { | |
return "Run"; | |
} | |
public String bite() { | |
return "Bite"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package oop.lesson2.homework.puppy; | |
public class Puppy extends Dog { | |
public Puppy(String name) { | |
super(name); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package oop.lesson2.homework.puppy; | |
public class PuppyRunner { | |
public static void main(String[] args) { | |
Puppy puppy = new Puppy("Ralf"); | |
System.out.println("Name: "+puppy.getName()); | |
System.out.println("Votes Cast: " + puppy.votesCast()); | |
System.out.println("Jump: " + puppy.jump()); | |
System.out.println("Run: "+ puppy.run()); | |
System.out.println("Bite: "+ puppy.bite()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment