+ 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?

15th Oct 2022, 10:08 PM
Dee
Dee - avatar
6 Answers
0
the link does not work
15th Oct 2022, 10:28 PM
Dee
Dee - avatar
0
thanks but there is no use of --
15th Oct 2022, 10:35 PM
Dee
Dee - avatar
0
Decrement like a--;
15th Oct 2022, 10:40 PM
Dee
Dee - avatar
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
15th Oct 2022, 10:57 PM
SoloProg
SoloProg - avatar
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() ?
15th Oct 2022, 11:45 PM
Dee
Dee - avatar
0
Dee , I didn't really understand your question and could you put your code.
16th Oct 2022, 7:45 PM
SoloProg
SoloProg - avatar