aspose file tools*
The moose likes Beginning Java and the fly likes Inheritance of a Variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance of a Variable" Watch "Inheritance of a Variable" New topic
Author

Inheritance of a Variable

Ravi Pydi
Greenhorn

Joined: Sep 01, 2002
Posts: 25
Iam an amateur to JAVA Programming. Iam working on a task where i should be reading a TEXT file as input and do some validations on the data.
Approach:
I have created a class(Validation.java). I have used DataInputStream to read the data. And the data is stored onto a String variable (say allData) using the readLine() method.
I have declared the varible as an instance variable in the super class.
public allData;
Then i have instantiated the class and the input stream.
Validation val = new Validation();
val.allData = instr.readLine();
//Note:Assuming the input stream is declaread and instantiated.
System.out.println(val.allData);
Iam getting the output that was desired. Now i have done some validations on the data and everything is working fine.
Now i want to use the same variable "allData" in another class.
I have created a subclass and EXTENDED the super class where "allData" variable exists. I have put both the classes into the same PACKAGE.
When i instantiated the subclass (ValidationSub) and printed the "allData" value iam getting null as output. But i want to get the output similar to the output i got in my superclass.
Note: i havent declared any variable in my subclass since it is already declared in the superclass.
How do i get the data assigned to my variable in superclass into my subclass?
I will be glad if anybody could suggest on this.
Thanking you,
Ravi Pydi
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Hi friend here's a sample test case:

How are you doing it?
 
Don't get me started about those stupid light bulbs.
 
subject: Inheritance of a Variable