Boyan5

OOP class Start

Nov 16th, 2021
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Start {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner input = new Scanner(System.in);
  7.  
  8.         System.out.print("Write first dog's name: ");
  9.         String firstDogName = input.nextLine();
  10.         // Assign dog name with a constructor
  11.         Dog firstDog = new Dog(firstDogName);
  12.  
  13.         System.out.print("Write second dog's name: ");
  14.         String secondDogName = input.nextLine();
  15.  
  16.         Dog secondDog = new Dog();
  17.  
  18.  
  19.         // Assign dog name with a property
  20.         secondDog.setName(secondDogName);
  21.  
  22.         // Create a dog with a default name
  23.         Dog thirdDog = new Dog();
  24.  
  25.         Dog[] dogs = new Dog[] { firstDog, secondDog, thirdDog };
  26.         for (Dog dog : dogs) {
  27.             dog.bark();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment