java - how do i print a "get" methods return value to console -
hello im trying out basic java skills.
here code
package bankaccount; public class test { string name; int houseno; int balance; test (string n,int h,int b) { n=name; h=houseno; b=balance; } int getbalance(){ return balance; } void setbalance(int newbalance){ newbalance = balance; } } //the class containing main package bankaccount; /** * * @author ideapc */ public class bankaccount { test t1 = new test("tim",147,5); system.out.println(t1.getbalance() + "name ="); public static void main(string[] args) { } }
i trying print balance of object t1 (tim) console using system.out.println
what doing wrong here?
put system.out.println()
inside main()
method.
public class bankaccount { public static void main(string[] args) { test t1 = new test("tim",147,5); system.out.println("name = "+t1.getbalance()); } }
you need change constructor of test
too.
test (string n,int h,int b) { this.name=n; this.houseno=h; this.balance=b; }
Comments
Post a Comment