【问题标题】:if i am using the setters getters to set the value in one method and i can get get the same value using getters to get it is possible? [closed]如果我使用setter getter 在一种方法中设置值并且我可以使用getter 获得相同的值来获得它是可能的吗? [关闭]
【发布时间】:2020-03-18 18:05:50
【问题描述】:

在下面的代码中,AccountServices 类中存在错误。在存款方法中我无法获得 d.accountNo();价值。它只是变为零。我不能用另一种方法调用之前设置的值?谁能给我解释一下??

System.out.println("The accno is "+d.getAcc_No()+" and Deposit amount was Rs."+balance);

这是代码....... https://github.com/moorthysmart/JdbcBank/tree/master/NetLogin

【问题讨论】:

    标签: java jdbc prepared-statement getter-setter


    【解决方案1】:

    您基本上是在不使用对象的情况下创建和销毁对象。

    您正在为对象设置值 登录方法中的 Dbsetget,但在存款方法中,您再次创建了一个新的 Dbsetget 对象,该对象当然是空的。

    为了重用对象及其值,您应该将对象作为方法参数传递或将它们声明为类/实例变量并使用 getter 方法

    【讨论】:

    猜你喜欢
    • 2019-04-19
    • 2017-01-05
    • 2019-01-16
    • 1970-01-01
    • 2013-11-12
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多