Menu
Topics Index
...
`

Class with multiple methods1879


If you need explanation Read this topic

If you need Answer Take test on this topic

Class with multiple methods1879
What will be the output of the following program?
public class SalaryIs {
    public static void main(String[] args) {
        Salary s = new Salary("Kiran", "Anantapur, AP", 3, 25000);
        System.out.println("Check the mail:- ");
        s.mailCheck();
    }
}
class Salary extends Employee {
    private double salary;
    public Salary(String name, String address, int number, double salary) {
        super(name, address, number);
        setSalary(salary);
    }
    public void mailCheck() {
        System.out.println("Check your mail Mr. " + getName() + " your salary is deposited " + salary);
    }
    public double getSalary() {
        return salary;
    }
    public void setSalary(double newSalary) {
        if (newSalary >= 0.0)
            salary = newSalary;
    }
    public double computePay() {
        System.out.println("Salary paid to " + getName());
        return salary / 52;
    }
}

class Employee {
    private final String name;
    public Employee(String name, String address, int number) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
}

A. Check the mail:- 
Check your mail Mr. Kiran your salary is deposited 25000.0
B. Check the mail:- 
Check your mail Mr. Kiran your salary is deposited 25000.0
Salary paid to Kiran
C. Check the mail:- 
Salary paid to Kiran
Check your mail Mr. Kiran your salary is deposited 25000.0
D. Check the mail:- 
Check your mail Mr. Kiran your salary is deposited 480.769
E. Some other output
F. Compilation Error or Runtime Error
Topic: Unknown

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans is A,since first Salary class constructor invoked and it calls its super class constructor then mailcheck method prints those private variable through getters

Posted by Raviteja Daggupati    2014-05-02 14:01:51


Ans is A. First Check the mail is printed and the s.mailCheck() invokes getName() which returns Kiran and the String is printed with the values substituted.... The remaining methods that have print statements have no function call. so they wont be printed..

Posted by Nikhil Sulibhavi    2014-05-02 14:09:13


Congratulations Raviteja Daggupati. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-05-05 04:39:45


© meritcampus 2019

All Rights Reserved.

Open In App