【问题标题】:how to write a print() method? Do I exclude static?how to write a print() method? Do I exclude static?
【发布时间】: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)

【问题讨论】:

标签: java methods


【解决方案1】:

Hey there @beginnerCoder,

You could go with the first one as it is possible to overload more than one static method.

Here is an example of what you are looking for,

https://www.geeksforgeeks.org/java-program-to-use-method-overloading-for-printing-different-types-of-array/

Hope this is what you are looking for.

【讨论】:

    猜你喜欢
    • 2022-11-20
    • 2022-12-19
    • 2022-12-27
    • 2022-12-27
    • 2022-12-02
    • 2022-01-04
    • 2022-12-28
    • 1970-01-01
    • 2022-12-01
    相关资源
    最近更新 更多