Object-Oriented Programming with Java, part I – Exercise 74

This program uses a method called multiplier to multiply numbers.

My Code

public class Multiplier {
    
    private int num;
    
    public Multiplier(int number){
        this.num = number;
    }
    
    public int multiply(int otherNumber){
        return this.num * otherNumber;
    }
    
}

Model Code

public class Multiplier {

 

    private int ownNumber;

 

    public Multiplier(int number) {

        this.ownNumber = number;

    }

 

    public int multiply(int otherNumber) {

        return this.ownNumber * otherNumber;

    }

}

 

Comments

Well, that was easy.

Leave a comment