java - How to set a value on a class using another class that is called/set in main class -
i have 3 classes, say: sharetype, sharetypestrue , main.
public class sharetype { public string sharetypename = ""; public string noofshare = ""; public string parvalue = ""; public void setsharetypename(string sharetypename) { this.sharetypename = sharetypename; } public void setnoofshare(string noofshare) { this.noofshare = noofshare; } public void setparvalue(string parvalue) { this.parvalue = parvalue; } } public class sharetypestrue { public list<sharetype> sharetype; public void setsharetype(list<sharetype> sharetype) { this.sharetype = sharetype; } } public class main { sharetypestrue sharetypetrue = new sharetypestrue(); sharetypetrue.add(sharetypename); }
now problem need set sharetypename value under class sharetypestrue. meaning have use sharetypestrue call on sharetype class , set sharetypename.
anyone has idea?
note: cant change/add code in first 2 classes except in main. need find way around this. alot
please check below code main class.
import java.util.arraylist; import java.util.list; public class main { public static void main(string args[]){ sharetypestrue sharetypetrue = new sharetypestrue(); //create object sharetype sharetype = new sharetype(); sharetype.setsharetypename("original name"); //create list list<sharetype> sharetypes=new arraylist<sharetype>(); sharetypes.add(sharetype); //attach share sharetypetrue.setsharetype(sharetypes); //print for(sharetype sharetypesmember:sharetypetrue.sharetype){ system.out.println(sharetypesmember.sharetypename); } //editing it. for(sharetype sharetypesmember:sharetypetrue.sharetype){ sharetypesmember.sharetypename = "updated name"; } //print for(sharetype sharetypesmember:sharetypetrue.sharetype){ system.out.println(sharetypesmember.sharetypename); } } }
Comments
Post a Comment