aspose file tools*
The moose likes Beginning Java and the fly likes Doubt in inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt in inheritance" Watch "Doubt in inheritance" New topic
Author

Doubt in inheritance

Dhivya rajagopal
Ranch Hand

Joined: Dec 15, 2010
Posts: 42


The above program displays the following error. can't we use the input in the sub classes.why?
cannot find symbol
symbol: variable a
location: class javaapplication7.inheritance1

cannot find symbol
symbol: variable b
location: class javaapplication7.inheritance1
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Two things:
  • Properly indent your code.
  • Tell us exactly what the error was. "There was an error" is not useful.


  • [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 40052
        
      28
    I would suggest you choose appropriate names for your classes, and capitalise them correctly. Calling a top-level class “inner” is by no means informative. And “inheritance1” is hardly better.
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19790
        
      20

    You can't put statements directly in a class body. They must go in a constructor, method or initializer block.


    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
    How To Ask Questions How To Answer Questions
    Randall Twede
    Ranch Hand

    Joined: Oct 21, 2000
    Posts: 4347
        
        2

    You can't put statements directly in a class body. They must go in a constructor, method or initializer block.

    i don't see that he did that? maybe he edited it. anyway the problem looks obvious to me. both a and b are local variables of class inner. make them member variables and things will probably work as intended.

    i take it back. the code makes no sense.
    if you eliminate lines 19-23 it will probably work as expected


    SCJP
    Visit my download page
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19790
        
      20

    Randall Twede wrote:
    You can't put statements directly in a class body. They must go in a constructor, method or initializer block.

    i don't see that he did that? maybe he edited it.

    Method add did not exist in the original post. Its code was put directly in the class. The method was "wrapped" around it afterwards.


    Dhivya rajagopal, please do not edit posts after it has been replied to. It can makes these replies look ridiculous; you can see the confusion it can cause right here.
    Sebanti Sanyal
    Ranch Hand

    Joined: Nov 07, 2011
    Posts: 58

    a and b are neither local variables, nor class members - they are non-existent as far as the second add() method is concerned. Perhaps your solution should be something like this:

    Dhivya rajagopal
    Ranch Hand

    Joined: Dec 15, 2010
    Posts: 42
    Hi, Sorry to all for editing the post. Hereafter i won't do that. Thank you
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Doubt in inheritance