aspose file tools*
The moose likes Java in General and the fly likes doubt in linked invocations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "doubt in linked invocations" Watch "doubt in linked invocations" New topic
Author

doubt in linked invocations

anita mitra
Greenhorn

Joined: Jul 03, 2009
Posts: 21

i have seen a prog like this

public class Addition{
public int doAddition(int a,int b){
int c=a+b;
return c;
}

public static void main(String[] args){
System.out.println(new Addition().doAddition(1,2);
}
}

suppose there is some other class in another package imports this class and calls doAdddition by passing 2 integer variables say 6,4 and gets 10. what about this line- System.out.println(new Addition().doAddition(1,2);. do it always passes (1,2) to doAddition method..

anita mitra
Greenhorn

Joined: Jul 03, 2009
Posts: 21

this is the program

public class SearchServiceImpl{
SearchServiceDAO searchServiceDAO = new SearchServiceDAOImpl();
/* assume
SearchServiceDAO package is imported in to this package(contains class SearchServiceDAOImpl which implements the interface searchServiceDAO

*/

public SearchServiceDAO getSearchServiceDAO() {
return searchServiceDAO;
}
public List<ServiceVO> searchServiceProviders(String serviceType) {

return searchServiceDAO.getServiceProvidersByServiceType(serviceType);
}

public static void main(String[] args){

SearchServiceImpl searchService = new SearchServiceImpl();
List<ServiceVO> serviceVOList = searchService.getSearchServiceDAO().getServiceProvidersByServiceType("FLIGHT");
for(ServiceVO serviceVO : serviceVOList){

System.out.println(serviceVO.getServiceId());
System.out.println(serviceVO.getServiceName());
System.out.println(serviceVO.getServiceType());
System.out.println(serviceVO.getServiceUrl());
}
}

}

i couldn't understand this line- List<ServiceVO> serviceVOList = searchService.getSearchServiceDAO().getServiceProvidersByServiceType("FLIGHT");


please explain. does this implies that it will always pass flight as service type to the method?
anita mitra
Greenhorn

Joined: Jul 03, 2009
Posts: 21

sushmita sen wrote:

cant understand. please explain
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
System.out.println(new Addition().doAddition(1,2);. do it always passes (1,2) to doAddition method..
yes... any reason that makes you think it should pass something else? see its not a variable but a literal and don't change
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
You show some piece of code of yours and ask us is "FLIGHT" passed as argument all the time? I think you can pass "CAR" or "TRAIN" or even "BULLOCK CART" as long as it is a service type. In this case, ENUM constant ServiceType should have been used as service type to help the client programmers
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doubt in linked invocations