Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in linked invocations

 
anita mitra
Greenhorn
Posts: 21
Eclipse IDE MySQL Database Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
Eclipse IDE MySQL Database Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
Eclipse IDE MySQL Database Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sushmita sen wrote:

cant understand. please explain
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic