Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method headers allowed by the compiler (simple Java exercise)

Tags:

java

I am practicing and the simple exercise is, given a FeatureFilm class defined to have the following methods:

public void update(Actor a, String title)
public void update(Actor a, Actor b, String title)
public void update(String topic, String title)

which of the following additional method headers would be allowed by the compiler?

public boolean update(String category, String theater)
public boolean update(String title, Actor a)
public void update(Actor b, Actor a, String title)
public void update(Actor a, Actor b)

So I did the code and the compiler doesn't allow this methods: public boolean update(String category, String theater) and public void update(Actor b, Actor a, String title), but I don't entirely understand why. Someone could explain this to me please? I hope to be making good use of this site. I'm a OPP beginner. Sorry about my (poor) English, Thanks.

like image 370
Nami Avatar asked Oct 26 '25 14:10

Nami


1 Answers

Because it is not allowed to have method with same Parameter types and different return type. So:

public void update(String topic, String title) and public boolean update(String category, String theater) has two strings as Parameter, but first one is a void and second one Returns a boolean value

like image 126
Jens Avatar answered Oct 29 '25 13:10

Jens