Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

java function

Posted on 2011-09-23
8
Medium Priority
?
327 Views
Last Modified: 2013-11-23
I saw a java code snippet which was something similiar to this

Fetch.func1().func2()

I understand that Fetch is a class and func1 is method in that class, but i am not sure what is func2 is it also a method in class fetch ? and also want to when can i use this type of function call...please help

~manu

 
0
Comment
Question by:manugeek
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 20

Expert Comment

by:a_b
ID: 36585454
Fetch.func1().func2() => Fetch is a class that has a method func1().

Fetch.func1() returns an object that has the method func2(), therefore you can invoke func2().
0
 
LVL 20

Assisted Solution

by:a_b
a_b earned 100 total points
ID: 36585457
Eg -

Class A
{
    public B func()1
   {
        .......
   }
}

Class B
{
   public void func()2
   {
        .......
   }  
}

You can try writting a test harness for these classes.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36585459
Well there is no gurantee in this notation, but one may assume that Fetch is a class, func1() is a static methid of this class which returns an instance of another class, and then method func2() is invojed on the instance of the result of funnc1()
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 100 total points
ID: 36585478
We can make conclusion that Fetch is a class and func1() is a static method because first letter of Fetch is capitalized and the convention is that class names are written starting with capital leeter
Howerver convention is not a law, so we cannot exclude that Fetch is an instance of some class. If so, then func1() would be an instance method - we should see more code to know for sure
0
 
LVL 13

Accepted Solution

by:
Hugh McCurdy earned 800 total points
ID: 36597016
I thought it might help to give an example from a program.  This example is from a simple interactive fiction ("adventure") game.

Path path = player.getRoom().getPath( direction );

Open in new window


Here the player is trying to leave the room he's currently in.  player is an object for the player.  getRoom() is a method in Player that returns the room the player currently occupies.  getPath() is a method in Room that accepts a compass direction and returns a path object (which may be null, meaning the direction is invalid).

The method continues.  I'm showing it just to give you some context.

If the path isn't null, we use a method in Path to get the room at the end of the path.  (The path can be very short, ie a door or doorway).

We have more "chained" messages (function calls).  I will explain what those do if you indicate it will help.  Better would be, if you can, explain to me what you think they do and get me (or someone) to review your answer.  (My assumption is you want to learn.)

        if ( path == null )
        {
            myScreen.setDescription ( "You can't go that way." );
        }
        else
        {
            Room nextRoom = path.getRoom();
            
            if ( player.getRoom().getPath ( direction ).getLocked())
            {
                myScreen.setDescription ( player.getRoom().getPath ( direction ).getWhyLocked() );
            }
            else // unlocked
            {
                if ( player.setRoom ( nextRoom ))
                myScreen.setDescription ( player.getRoom() );
            } // else
                
        } // else

Open in new window



0
 

Author Comment

by:manugeek
ID: 36597255
Thank @hmccurdy: for the detailed explanation. Now this makes sense to me :-)

0
 

Author Closing Comment

by:manugeek
ID: 36597259
Thanks all for the answers...
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36598821
Thanks.  Never mind for the program bug that remained (oops) after I removed some lines of code that would be confusing.

I'm glad it makes sense to you now.  Gets my day off to a good start.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question