Results 1 to 6 of 6
- 04-22-2011, 10:07 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 30
- Rep Power
- 0
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? :)
- 04-22-2011, 10:20 AM #2
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
- 04-22-2011, 10:21 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 04-22-2011, 11:23 AM #4
Member
- Join Date
- Apr 2011
- Posts
- 30
- Rep Power
- 0
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;
}
}
- 04-22-2011, 11:41 AM #5
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
- 04-22-2011, 01:42 PM #6
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
-
Reflection Invoking method of "super" class
By Shellback3 in forum Advanced JavaReplies: 2Last Post: 01-31-2011, 04:50 PM -
super class reference variable accesses overriding sub class method
By subith86 in forum New To JavaReplies: 5Last Post: 01-26-2011, 06:38 PM -
how to call higher level super class method?
By satheeshtech in forum Advanced JavaReplies: 2Last Post: 01-12-2010, 03:11 PM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM -
Class Reflection: Finding super class names
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks