Results 1 to 6 of 6
  1. #1
    rbradleyjr is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Illegal Start of Type

    I am getting this error message at the statement:

    "class B extends class A"

    / A simmple example of inheritance.

    // Create a superclass.
    class A {
    int i, j;

    void showij() {
    System.out.println( "i and j: " + i + " " + j );
    // A simmple example of inheritance.


    }
    }


    // Create a subclss by extending class A.
    class B extebds class A {
    int k;

    void showk() {
    System.out.println( "k: " + k );
    }

    void sum() {
    System.out.println( "i+j+k: " + (i+j+k) );
    }
    }


    class SimpleInheritance {
    public static void main( String args[] ) {
    A superOb = new A();
    B subOb = new B();

    // the superclass may be used by itself
    superOb.i = 10;
    superOb.j = 20;

    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Illegal Start of Type

    Which line causes the error?

    Immediately one can see though that this is not spelled correctly:

    Java Code:
    class B extebds class A {
    Remember that the java compiler is not very forgiving.

  3. #3
    rbradleyjr is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Illegal Start of Type

    Sorry, everything is spelling correct.
    I'm getting the error at the line "class B extends class A"

    / A simmple example of inheritance.

    // Create a superclass.
    class A {
    int i, j;

    void showij() {
    System.out.println( "i and j: " + i + " " + j );
    // A simmple example of inheritance.


    }
    }


    // Create a subclss by extending class A.
    class B extends class A {
    int k;

    void showk() {
    System.out.println( "k: " + k );
    }

    void sum() {
    System.out.println( "i+j+k: " + (i+j+k) );
    }
    }


    class SimpleInheritance {
    public static void main( String args[] ) {
    A superOb = new A();
    B subOb = new B();

    // the superclass may be used by itself
    superOb.i = 10;
    superOb.j = 20;

    }
    }

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Illegal Start of Type

    Quote Originally Posted by rbradleyjr View Post
    Sorry, everything is spelling correct.
    I'm getting the error at the line "class B extends class A"
    Then there's your problem because that's not the syntax for having one class extend another. You would say -- class B extends A -- without the second "class" word.

    Also, please look up how to use code tags in this forum as it will make helping you loads easier.

  5. #5
    rbradleyjr is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Illegal Start of Type

    Geezz...am I stupid. ;-).
    I even copied it wrong from the book I'm using.
    Well, I've only been programmng in Java for 3 days.
    Good 1st lesson of many to come.

    Thanks a million.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Illegal Start of Type

    Quote Originally Posted by rbradleyjr View Post
    Geezz...am I stupid. ;-).
    I even copied it wrong from the book I'm using.
    Well, I've only been programmng in Java for 3 days.
    Good 1st lesson of many to come.
    Welcome to the "fall on your face many times while learning to program" club. We have many many members, and I'm the club president.


    Thanks a million.
    You're welcome, and welcome to the forum!

Similar Threads

  1. Illegal start of type
    By peteosmith in forum AWT / Swing
    Replies: 3
    Last Post: 08-13-2011, 06:03 PM
  2. Illegal Start of Expression
    By Tyre in forum New To Java
    Replies: 20
    Last Post: 04-15-2011, 03:50 PM
  3. illegal start of expression
    By rajivjoshi in forum New To Java
    Replies: 3
    Last Post: 05-31-2010, 10:12 AM
  4. <identifier> expected, illegal start of type
    By masberry in forum New To Java
    Replies: 1
    Last Post: 11-02-2009, 08:45 PM
  5. Illegal start of expression
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 06:09 PM

Posting Permissions

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