In [1]:
public class Operacao {
public int soma(int n1, int n2) {
return n1 + n2;
}
}
Out[1]:
In [2]:
Operacao op = new Operacao();
System.out.println(op.soma(10, 15));
Out[2]:
In [3]:
public class Operacao {
public int soma(int n1, int n2) {
return n1 + n2;
}
public int soma(String n1, int n2) {
return Integer.parseInt(n1) + n2;
}
public int soma(int n1, String n2) {
return n1 + Integer.parseInt(n2);
}
public int soma(String n1, String n2) {
return Integer.parseInt(n1) + Integer.parseInt(n2);
}
}
Out[3]:
In [4]:
Operacao op = new Operacao();
System.out.println(op.soma(10, "15"));
System.out.println(op.soma("10", 15));
System.out.println(op.soma("10", "15"));
Out[4]:
In [5]:
public class Operacao {
public int soma(int n1, int n2) {
return n1 + n2;
}
public int soma(int n1, String n2) {
return soma(n1, Integer.parseInt(n2));
}
public int soma(String n1, int n2) {
return soma(Integer.parseInt(n1), n2);
}
public int soma(String n1, String n2) {
return soma(Integer.parseInt(n1), Integer.parseInt(n2));
}
}
Out[5]:
In [6]:
Operacao op = new Operacao();
System.out.println(op.soma(10, "15"));
System.out.println(op.soma("10", 15));
System.out.println(op.soma("10", "15"));
Out[6]:
In [7]:
public class Operacao {
public int soma(int n1, int n2) {
return n1 + n2;
}
}
Out[7]:
In [8]:
public class OperacaoExtra extends Operacao {
public int soma(int n1, String n2) {
return soma(n1, Integer.parseInt(n2));
}
public int soma(String n1, int n2) {
return soma(Integer.parseInt(n1), n2);
}
public int soma(String n1, String n2) {
return soma(Integer.parseInt(n1), Integer.parseInt(n2));
}
}
Out[8]:
In [9]:
OperacaoExtra op = new OperacaoExtra();
System.out.println(op.soma(10, "15"));
System.out.println(op.soma("10", 15));
System.out.println(op.soma("10", "15"));
Out[9]: