Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Pet myPet = new Pet();
- System.out.println("Action: Invoking move() method of the Pet object");
- System.out.print("Output: ");
- myPet.move();
- System.out.println();
- System.out.println("Action: Invoking givecompanionship(1) method");
- System.out.print("Output: ");
- myPet.givecompanionship(1);
- System.out.println();
- System.out.println("Action: Invoking givecompanionship(3) method (multiple repetitions)");
- System.out.println("Output:");
- myPet.givecompanionship(3);
- }
- }
- class Pet {
- public void move() {
- System.out.println("The pet has moved.");
- }
- public void givecompanionship(int n) {
- for (int i = 0; i < n; i++) {
- System.out.println("The pet is giving you companionship.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment