Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java function

Posted on 2011-09-23
8
Medium Priority
?
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

704 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