Results 1 to 4 of 4

Thread: Inheritance

  1. #1
    Rubel Rana is offline Member
    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0

    Default Inheritance

    Java Code:
    
    
    class A{
    	
    	System.out.println("Inside A");  ***
    	
    }
    class B extends A{
    	System.out.println("Inside B"); ***
    }
    
    class C extends B{
    	System.out.println("Inside C"); ***
    }
    
    public class a{
    	public static void main(String[] args){
    		C c = new C();
    	}
    }
    Ques:In every '***' place,it shows error,whats the problem with this??

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: Inheritance

    Because you can't just put code anywhere you like and expect it to work. Function calls need to be inside a method or static block, except for declarations.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Inheritance

    You can't have statements at class level. They must be inside a constructor, method, a static block or even a non-static block, but not there. Your example would work if you move these to a constructor.

  4. #4
    Rubel Rana is offline Member
    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0

Similar Threads

  1. Inheritance
    By NewToJava_99 in forum New To Java
    Replies: 2
    Last Post: 05-20-2012, 08:03 PM
  2. Help with inheritance
    By waker3210 in forum Java Gaming
    Replies: 6
    Last Post: 05-19-2012, 08:27 PM
  3. inheritance
    By FREDISCO in forum New To Java
    Replies: 2
    Last Post: 03-27-2012, 02:11 AM
  4. Inheritance
    By new_2_j in forum New To Java
    Replies: 5
    Last Post: 02-20-2011, 05:56 PM
  5. Inheritance in GUI
    By Marty in forum SWT / JFace
    Replies: 2
    Last Post: 05-11-2007, 12:54 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
  •