Results 1 to 2 of 2
  1. #1
    harukia is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Default Problems adding new method to an extending abstract class

    In the program class:
    ...
    URL url = new URL("http://www.google.com");
    extURLConnection c = new extURLConnection(url.openConnection());
    ...
    if (c.isConnected){
    ...

    In URLConnection I cant access the attribute connected (that shows if i got a connection or not). so I want to add a method that return that attribute.

    So I created a class called extURLConnection that extends URLConnection. As method connect() is abstract I must define this class as abstract. And this is here I get problems. Cause of this i cant initiate this class (as i written above). So how do I implement this isConnected method? Is it possible to do it in another way? I've read some thing about Interfaces, can it be done with that?

    import java.net.*;
    class DpURLConnection extends URLConnection{
    DpURLConnection(URLConnection URLConn){
    super(URLConn.getURL());
    }

    public boolean isConnected(){
    return this.connected;
    }
    }

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    You can't do this, at least not without writing your own versions of HttpURLConnection etc.

    Why do you need to know about the connected flag? It's for internal use only.

Similar Threads

  1. Replies: 3
    Last Post: 08-13-2010, 04:57 AM
  2. Replies: 3
    Last Post: 09-16-2009, 09:27 PM
  3. Replies: 6
    Last Post: 02-11-2009, 10:51 AM
  4. Replies: 2
    Last Post: 11-21-2008, 12:20 AM
  5. Problems adding an external class
    By jan2321 in forum Eclipse
    Replies: 2
    Last Post: 11-06-2008, 10:34 AM

Posting Permissions

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