Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Inheritance not working!

  1. #1
    Member
    Join Date
    Apr 2011
    Posts
    32
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default Inheritance not working!

    Hey everyone, I am basically trying to just use the super keyword to call my subclass:

    public class SenderReceiver extends MultiEchoClient{
     
    		public SenderReceiver(String host,int port){
    			super(host,port);
    		}
     
    		public static void main(String args[]){
    			if(args.length == 0){
    			SenderReceiver senderReceiver = new SenderReceiver((String) "127.0.0.1",4433);
    		}else{
    			SenderReceiver senderReceiver = new SenderReceiver(args[0],4433);
    		}
    		//SenderReceiver.run();
    		}
    }

    The super class has a constructor that passes String host,int port and so I am just trying to call that. I want to be able to have all the functionality in this new class so that if i mess up, then my superclass will be okay!

    The compile error that i get is "unreported exception, must be caught or thrown". It is an IOException so I tried to encase the super(host,port); with a try catch block but it says that the super keyword must be declared first...

    Thanks!


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: Inheritance not working!

    Declare the constructor to throw the exception - this will force any code that constructs a SenderReceiver to throw or catch the exception. See Lesson: Exceptions (The Java™ Tutorials > Essential Classes)

  3. The Following User Says Thank You to copeg For This Useful Post:

    u-will-neva-no (March 20th, 2012)

  4. #3
    Member
    Join Date
    Apr 2011
    Posts
    32
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default Re: Inheritance not working!

    Thanks for the reply. I tried this:

    public SenderReceiver(String host,int port)throws IOException{
    			super(host,port);
    		}
    but get a "cannot retrieve symbol"

  5. #4
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: Inheritance not working!

    Post the full error. Did you import java.io.IOException?

  6. The Following User Says Thank You to copeg For This Useful Post:

    u-will-neva-no (March 20th, 2012)

  7. #5
    Member
    Join Date
    Apr 2011
    Posts
    32
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default Re: Inheritance not working!

    ah, it looks like my objects were causing the issue. I shall have a look to see why that is. The throws IOException did the trick, thanks for your help copeg, much appreciated!

Similar Threads

  1. Inheritance
    By lewzax in forum Object Oriented Programming
    Replies: 4
    Last Post: July 8th, 2011, 01:51 PM
  2. Java Inheritance Help
    By danielparry in forum Java Theory & Questions
    Replies: 3
    Last Post: March 17th, 2011, 03:20 PM
  3. inheritance help
    By justin3492 in forum Object Oriented Programming
    Replies: 3
    Last Post: September 30th, 2010, 07:45 PM
  4. inheritance
    By b109 in forum Java Theory & Questions
    Replies: 3
    Last Post: May 30th, 2010, 09:23 PM
  5. Replies: 4
    Last Post: January 26th, 2009, 11:03 PM