How to use set method of a different class in java? -
how can set value of parameter of class a
in class b
using setvara
method of class a
?
public class a{ string vara; public string getvara() { return vara; } public void setvara(string vara) { this.vara=vara; } } public class b{ string name = "abc"; obja = new a(); obja.setvara(name) ; ## lines throws error }
the error is:
syntax error on token "name", variabledeclaratorid expected after token , syntax error on token(s), misplaced constructs
public class a{ string vara; public string getvara() { return vara; } public void setvara(string vara) { this.vara=vara; } } class b { string name = "abc"; obja = new a(); b() { obja.setvara(name); } }
Comments
Post a Comment