+ 1
help in java
i have class variable and i have to use set() get() then i want to call it by using get() and do -- How can i do that?
6 Answers
0
the link does not work
0
thanks
but there is no use of --
0
Decrement
like a--;
0
// Dee , I hope this code helps you
class Main {
public static void main(String[] args) {
Account a = new Account();
a.setBalance(100);
System.out.println("Balance: " + a.getBalance());
a.setDecrement();
System.out.println("Balance (decreased): " + a.getBalance());
}
}
class Account {
private int num;
public int getBalance() { // Getter
return this.num;
}
public void setBalance(int n) { // Setter
this.num = n;
}
public void setDecrement() { // Setter
this.num = --this.num;
}
}
https://www.sololearn.com/compiler-playground/caW1vgzWJ0mT
0
why in setDecrement()
i use the name num
when i already have a get() to return it
How can i use it with get() ?
0
Dee ,
I didn't really understand your question
and could you put your code.