• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing a String

 
Shamsudeen Akanbi
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4469
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im not even going to read your example. the answer is yes
 
Campbell Ritchie
Sheriff
Pie
Posts: 49862
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49862
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I mean ...CorporateRipoff. A completely different class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic