943,589 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 341
  • Java RSS
Nov 28th, 2008
0

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

Expand Post »
Hi Frnds,
Sorry For The Spam .

i have a class name"Super"
program:
Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 1
Light Poster
babusek is offline Offline
28 posts
since Oct 2008
Nov 28th, 2008
0

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

your app bit more OO-minded

Java Syntax (Toggle Plain Text)
  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. }

Java Syntax (Toggle Plain Text)
  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
Reputation Points: 919
Solved Threads: 354
Nearly a Posting Maven
stultuske is offline Offline
2,473 posts
since Jan 2007
Nov 28th, 2008
0

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

@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.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Commapi serial port close/open
Next Thread in Java Forum Timeline: how to send message via bluetooth





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC