mardi 22 mars 2016

Java access to members with type conversion

I have problem with understanding how the methods below work. I have class Calc and method for multiplication, first method use typical getters, second method can access straight to private attribute with type conversion. My question is, how it is possible, that number1 have access to number2's private attribute.

private int number;

public Calc multiplication(Calc z)
 {
        return new Calc(this.number*z.getNumber());
 }

 public Calc multiplication(Calc z)
 {
        return new Calc(this.number*((Calc)z).number);
 }

test()
{
number1 = new Calc(2);
number2 = new Calc(3);
number1.multiplication(number2);
}



Java access to members with type conversion

Aucun commentaire:

Enregistrer un commentaire