Solved

java function

Posted on 2011-09-23
8
310 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
Industry Leaders: 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 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
 
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

Technology Partners: 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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

713 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