Results 1 to 10 of 10
  1. #1
    Michail235 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default Where are the methods

    I want to study Java, a programming experience in C, Pascal, Delphi, Assembler, PHP. Textbooks do not have time to read, study the source code.
    Question:
    In a class there is a method, on all it is visible that library. From what libraries it is taken?
    For example, the class Calculator, extension of the class Applet. In it there is a method setLayout. JDK documentation for the method setLayout occurs in 10 classes, including JApplet, but none of the Applet.
    So where is the compiler takes this method? and how do find out which class belongs to one or another method?
    Thank you

  2. #2
    santeron is offline Member
    Join Date
    Apr 2011
    Location
    Athens, Greece
    Posts
    52
    Rep Power
    0

    Default

    Well I guess this is what you ask (not 100% sure it goes exactly like this but it should be something close):

    First of all it'll look inside your class in case you have override the method you want to call or you have one named like that. Then it checks the imported packages if they have it. Then the standard library. It will not check a package if you haven't imported it at the begging.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default

    Quote Originally Posted by santeron View Post
    Then it checks the imported packages if they have it.
    No it won't
    Java Code:
    import java.awt.Point;
    
    class MyClass extends AnotherClass {
        public void someMethod() {
            doStuff();
        }
    }
    In the above code the compiler will try to find the doStuff method in the MyClass class. If it doesn't exist it will look in the parent class AnotherClass and so on up the inheritance chain all the way to Object. It will never look in the Point class.

  4. #4
    santeron is offline Member
    Join Date
    Apr 2011
    Location
    Athens, Greece
    Posts
    52
    Rep Power
    0

    Default

    Well yeah you are right... You should state you need a method from that package like Point.doStuff()... :o

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,953
    Rep Power
    19

    Default

    Quote Originally Posted by Michail235 View Post
    I want to study Java, ... Textbooks do not have time to read.
    How about tutorials?

    Because if you're not willing to even do that then, frankly, I wouldn't give you a job.

  6. #6
    Michail235 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    2Junky
    When will the chain in your example?.
    MyClass -> AnotherClass -> java.awt.Point
    This is all? Do I understand correctly?

    2Tolls
    You know, I'm at an age where it is important not work, and important interest. Therefore, I'm not interested wage work, and are interested in the embodiment of my project.

  7. #7
    santeron is offline Member
    Join Date
    Apr 2011
    Location
    Athens, Greece
    Posts
    52
    Rep Power
    0

    Default



    Uploaded with ImageShack.us
    This is from the book O'Reilly Head First Java (Kathy Sierra & Bert Bates) (chapter Inheritance and Polymorphism (p. 175)). Maybe it makes it clear.

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default

    Quote Originally Posted by Michail235 View Post
    2Junky
    When will the chain in your example?.
    MyClass -> AnotherClass -> java.awt.Point
    This is all? Do I understand correctly?
    No it is not correct. I imported a randomly chosen class just to highlight the misinformation provided. If AnotherClass does not extend any other class then the inheritance heirarchy is Object > AnotherClass > MyClass. These are the only classes where the method can be found. The point (pardon the pun) I was trying to make by importing the Point class is that it will never expect to find the method in classes that are imported (unless the imported class is also the class being extended).

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,953
    Rep Power
    19

    Default

    Quote Originally Posted by Michail235 View Post
    2Tolls
    You know, I'm at an age where it is important not work, and important interest. Therefore, I'm not interested wage work, and are interested in the embodiment of my project.
    Except for the fact that if you want to be any good at this then the books (especially the one santeron quotes from, which is one of the best) and the tutorials are required.

    Or are you expecting us to teach you?

  10. #10
    Michail235 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    All thank you very much.
    I think I've figured out the issue

    Quote Originally Posted by Tolls View Post
    Or are you expecting us to teach you?
    Of course! I believe that any communication is to study. Hence, asking a question and get an answer, we learn.
    So I say: thank you for what you have learned what I knew.
    Incidentally, this book, I have not heard, because I have not seen her. I live in Russia.

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Methods Please help
    By bdario1 in forum New To Java
    Replies: 33
    Last Post: 03-25-2010, 03:26 AM
  3. Help with get and set methods
    By shroomiin in forum New To Java
    Replies: 4
    Last Post: 11-23-2009, 08:04 PM
  4. Replies: 4
    Last Post: 04-03-2009, 06:36 AM
  5. JSP methods example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-30-2008, 10:00 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
  •