Solved

java function

Posted on 2011-09-23
8
299 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 25 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
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 25 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 13

Accepted Solution

by:
Hugh McCurdy earned 200 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

758 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now