Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Java Quiz 14: Overloading Methods

DZone's Guide to

Java Quiz 14: Overloading Methods

Get caught up with the answer to the previous quiz on passing objects to a method, and try your hand at this quiz, which deals with overloading methods.

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

Before we start with this week's quiz, here is the answer to Java Quiz 13: Passing Objects to a Method.

It seems that the references of the objects sb and sb2 are passed to the method myMethod,
but in fact, the values of the objects are passed to the method. Therefore,
the statement s1 = s2; doesn't change the output of the program.

The correct answer is: B.

Here is the quiz for today!

What is the output of the following code?

public class MyClass {
    public void writeValue(int a, byte b) {
        System.out.println("Byte " + a + b);
    }
    public void writeValue(int a, short b) {
        System.out.println("Int " + a + b);
    }
    public void writeValue(int a, Integer b) {
        System.out.println("Integer " + a + b);
    }
    public void write Value(int a, double b) {
        System.out.println("Double " + a + b);
    }
    public static void main(String[] args) {
        new MyClass().writeValue(2, 5);
    }
}


  • A. This program writes "Integer 25" to the standard output.
  • B. This program writes "Int 25" to the standard output.
  • C. This program writes "Byte 25" to the standard output.
  • D. This program writes "Double 25.0" to the standard output.
  • E. Runtime exception.
  • F. Compilation error.

The correct answer and its explanation will be included in the next quiz in two weeks! For more Java quizzes, puzzles, and assignments, take a look at my site!

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:
java ,overloading

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}