Results 1 to 6 of 6
  1. #1
    elenora is offline Member
    Join Date
    Apr 2011
    Posts
    30
    Rep Power
    0

    Smile problem in set & get method of a super class

    I implemented two classes named First and Second, which extended from a super class, in super class I wrote two set and get methods. In First class I call the set method and assign a String value to it and in second class I call the get method to get the value but in the second class, the get method has null value! If I call the get method in First class, the get method has a value which I assigned to the set method! I want to ask, could anyone help me what can I do for get method to doesnítí have null value in second class? :)

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    I guess you create two instance for first and second class, Then you want take value from first to second class. You can't it.
    Can you show your code? and elaborate what aim do you want to achieve?
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,348
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by elenora View Post
    I implemented two classes named First and Second, which extended from a super class, in super class I wrote two set and get methods. In First class I call the set method and assign a String value to it and in second class I call the get method to get the value but in the second class, the get method has null value! If I call the get method in First class, the get method has a value which I assigned to the set method! I want to ask, could anyone help me what can I do for get method to doesn’t’ have null value in second class? :)
    Show us the (relevant) code; probably you're assigning a value to your method parameter instead of to your member variable.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    elenora is offline Member
    Join Date
    Apr 2011
    Posts
    30
    Rep Power
    0

    Red face

    public class First() extends MyTextBox{
    protected void keyPressed(int keyCode) {
    if(keyCode==-6){
    setTempSin(text);
    }
    }

    public class Second() extends MyTextBox{
    String tempString;
    public Second() {
    tempString=getTempSin();
    }
    }

    public class MyTextBox(){
    String tempStr;
    public MyTextBox() {
    }
    public void setTempSin(String str){
    this.tempstr=str;
    System.out.println(tempstr);
    }
    public String getTempSin(){
    return this.tempstr;

    }
    }

  5. #5
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    Can you show a main method? How are you testing a code?

    edit:

    and where did you find this syntax?

    What is this?
    Java Code:
    class MyTextBox[B]()[/B] {
    Last edited by Petr; 04-22-2011 at 11:50 AM.
    Skype: petrarsentev
    http://TrackStudio.com

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by elenora View Post
    I implemented two classes named First and Second, which extended from a super class, in super class I wrote two set and get methods. In First class I call the set method and assign a String value to it and in second class I call the get method to get the value but in the second class, the get method has null value! If I call the get method in First class, the get method has a value which I assigned to the set method! I want to ask, could anyone help me what can I do for get method to doesnítí have null value in second class? :)

    first of all your class declarations are wrong. learn first how to define classes, for example here. secondly, java is case sensitive. so if you declare a field with the name tempStr you can't refer it with tempstr. and last point: where does the variable text in the method First() come from?

Similar Threads

  1. Reflection Invoking method of "super" class
    By Shellback3 in forum Advanced Java
    Replies: 2
    Last Post: 01-31-2011, 04:50 PM
  2. Replies: 5
    Last Post: 01-26-2011, 06:38 PM
  3. how to call higher level super class method?
    By satheeshtech in forum Advanced Java
    Replies: 2
    Last Post: 01-12-2010, 03:11 PM
  4. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  5. Class Reflection: Finding super class names
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •