We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 90c1f26 commit ce61810Copy full SHA for ce61810
1 file changed
Runtime Polymorphism/Main.java
@@ -0,0 +1,23 @@
1
+import java.util.Scanner;
2
+
3
+public class Main {
4
+ public static void main(String[] args) {
5
6
+ Scanner scanner = new Scanner(System.in);
7
8
+ System.out.print("Would you like a dog or a cat? (1 = dog, 2 = cat): ");
9
+ int choice = scanner.nextInt();
10
11
+ Animal animal;
12
13
+ if(choice == 1) {
14
+ animal = new Dog();
15
+ animal.speak();
16
+ } else {
17
+ animal = new Cat();
18
19
+ }
20
21
+ scanner.close();
22
23
+}
0 commit comments