This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Passing a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing a String " Watch "Passing a String " New topic
Author

Passing a String

Shamsudeen Akanbi
Ranch Hand

Joined: Dec 24, 2010
Posts: 72
Is it possible to pass in to a method that accepts a String a method that returns a String I mean:
class FootballClub {
public void manager(String name) { }
}

class ManchesterUnited extends FootballClub {
public String setName() {
String name = "Alex";
return name;
}
public static void main (String[] args) {
FootballClub fc = new FootballClub();
fc.manger(setName());
}
}


I know there are other ways to set it but is it possible to pass a method that accept a String as I said. Thank you guys in advance.


James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Yes you can is the answer.

Consider revising your naming of methods. Something like setName() would normally not return anything and take a String as a parameter.

Also, disgusting code simply because it has the words Manchester United in it
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

im not even going to read your example. the answer is yes


SCJP
Visit my download page
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
It is not right for a class called ManchesterUnited or even ManchesterCity to extend FootballClub. ManchesterUnited is an instance of a FootballClub, not a sub-type.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Sorry, I mean ...CorporateRipoff. A completely different class.
 
Don't get me started about those stupid light bulbs.
 
subject: Passing a String