Menu
Question Index
...

What will be the output of the following program?

class MeritSchool {
    private final String string1, string2;
    public MeritSchool(String string2, String string1) {
        this.string1 = string2;
        this.string2 = string1;
    }
    public String toString() {
        return string1 + " " + string2 + " School";
    }
    public static void main(String[] args) {
        MeritSchool print = new MeritSchool("Merit", "Campus");
        System.out.println(print);
    }
}


Campus Merit School
Merit Campus School
Merit Campus
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java String Conversion - toString() Method In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App