How to Access a Public Filed from a class and that Field value From the other Class

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 26
Reputation: babusek is an unknown quantity at this point 
Solved Threads: 1
babusek babusek is offline Offline
Light Poster

How to Access a Public Filed from a class and that Field value From the other Class

 
0
  #1
Nov 28th, 2008
Hi Frnds,
Sorry For The Spam .

i have a class name"Super"
program:
  1. package turn;
  2. public class Super {
  3. public static String platformFlag=null;
  4.  
  5. public void parse()
  6. {
  7. platformFlag="Sekhar";
  8. }
  9. public static void main(String args[])
  10. {
  11. Super ob=new Super();
  12. ob.parse();
  13. }
  14. }
  15. -------------------------------------------------------------------------------
  16. Now i have another class in the same package
  17. package turn;
  18. public class Model {
  19. public void result(Super dupObj){
  20. :'( System.out.println("Value of platformFlag" +dupObj.platformFlag);
  21. }
  22. public static void main(){
  23. Model my=new Model();
  24. Super sObject = new Super();
  25. my.result(sObject);
  26. }
  27. }
  28.  
---------------------------------------------------------------------------------
but when iam printing the value of platformFlag from the class Model it is printing null.. .?

could anyone of here tell me wat is the reason .
and Tell me the rway how to print value as sekhar
Last edited by ~s.o.s~; Nov 28th, 2008 at 9:00 am. Reason: Added code tags, learn to use them.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: How to Access a Public Filed from a class and that Field value From the other Class

 
0
  #2
Nov 28th, 2008
your app bit more OO-minded

  1. package turn;
  2. public class Super {
  3. private String platformFlag=null;
  4.  
  5. public Super(){
  6. setPlatformFlag("sekhar");
  7. }
  8.  
  9. public void setPlatformFlag(String in){
  10. this.platformFlag = in;
  11. }
  12.  
  13. public String getPlatformFlag(){
  14. return this.platformFlag;
  15. }
  16. }

  1. package turn;
  2. public class Model {
  3. public void result(Super dupObj){
  4. System.out.println("Value of platformFlag" + dupObj.getPlatformFlag());
  5. }
  6. public static void main(){
  7. Model my=new Model();
  8. Super sObject = new Super();
  9. my.result(sObject);
  10. }
  11. }
Last edited by stultuske; Nov 28th, 2008 at 8:53 am. Reason: access identifier corrected
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: How to Access a Public Filed from a class and that Field value From the other Class

 
0
  #3
Nov 28th, 2008
@babusek
This is your twentieth post and still you have not used code tags. Are you just plain ignorant to not go through the Community rules or the Announcements or at least observe how other posters post in the forum.
Last edited by stephen84s; Nov 28th, 2008 at 8:50 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC