Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Start {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Write first dog's name: ");
- String firstDogName = input.nextLine();
- // Assign dog name with a constructor
- Dog firstDog = new Dog(firstDogName);
- System.out.print("Write second dog's name: ");
- String secondDogName = input.nextLine();
- Dog secondDog = new Dog();
- // Assign dog name with a property
- secondDog.setName(secondDogName);
- // Create a dog with a default name
- Dog thirdDog = new Dog();
- Dog[] dogs = new Dog[] { firstDog, secondDog, thirdDog };
- for (Dog dog : dogs) {
- dog.bark();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment