Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with super()

Status
Not open for further replies.

mackey333

Technical User
May 10, 2001
563
US
Hi all...I am having a strange problem with a class I am working on...any ideas?

Code:
import java.io.*;
public class Program extends File
{
	Program(String targetLNK) throws Exception 
	{
		super(targetLNK);
		
		System.out.println(targetLNK);
		
                System.out.println(super.toString());
                System.out.println(super.getAbsolutePath());
         }
}

When I run the constructor and print targetLNK, the file path is printed correctly. However the super.toString() and super.getAbsolutePath() both come back as null. Any thoughts?

-Greg :-Q

flaga.gif
 
Is the path indicated by the value in targetLNK actually a valid one with respect to the filesystem?

Tim
 
What happens if you call those methods outside the constructor, or without super keyword?

Cheers,
Dian
 
Changing the class to work with a file object instead of super() works perfectly:

Code:
import java.io.*;
public class Program
{
	Program(String targetLNK) throws Exception 
	{
		f = new File(targetLNK);
		
		System.out.println(f.getAbsolutePath());
      }
}

Now I am really confused.

-Greg :-Q

flaga.gif
 
Also in the original code, super.getAbsolutePath() and getAbsolutePath() both returned a null value. The same goes for getPath() in both cases (with and without super).

-Greg :-Q

flaga.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top