【发布时间】:2022-11-20 12:21:20
【问题描述】:
Overloaded methods: Users can use a print() method to print any of the following: a single string; two double values; or an integer and a string. Write three separate method headers (no method bodies) for print ().
Through research I found that the print() method is written like this:
public void print()
But I've only learned to write methods
that include static.
Is it possible to write a print() method like this?:
public static void print()
could the solution be:
public static void print(String a) or is it public void print(String a)
【问题讨论】:
-
even though your class assignment says not to create method bodies, you can write test code to try both approaches and see which works.
-
see docs.oracle.com/javase/tutorial/java/javaOO/methods.html for defining function signatures.