Menu
Question Index
...

What will be the output of the following program?

public class TomAndJerry {
    int tomAge = 5;
    String name = "Tommy";
    public TomAndJerry(String name) {
        System.out.println("Name is : " + name);
    }
    public void getAge(int age) {
        tomAge = age;
    }
    public int getAge() {
        System.out.println("Tom's age is : " + tomAge);
        return tomAge;
    }
    public static void main(String[] args) {
        TomAndJerry tom = new TomAndJerry("Tom");
        tom.getAge(2);
        tom.getAge();
        System.out.println("Value : " + tom.tomAge);
    }
}


Name is : Tommy
Tom's age is : 2
Value : 5
Name is : Tom
Tom's age is : 5
Value : 5
Name is : Tom
Tom's age is : 2
Value : 2
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Multiple Methods In One Class

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App