File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing a String " Watch "Passing a String " New topic

Passing a String

Shamsudeen Akanbi
Ranch Hand

Joined: Dec 24, 2010
Posts: 83
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();

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

Joined: Nov 09, 2011
Posts: 1051

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: 4351

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

Visit my download page
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46368
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

Joined: Oct 13, 2005
Posts: 46368
Sorry, I mean ...CorporateRipoff. A completely different class.
I agree. Here's the link:
subject: Passing a String
It's not a secret anymore!