Knowee
Questions
Features
Study Tools

Choose the appropriate return type for the getters and setters provided below. class Test{private int value;public setValue(int value){//some code}public getValue(){//some code}}

Question

Choose the appropriate return type for the getters and setters provided below. class Test{private int value;public setValue(int value){//some code}public getValue(){//some code}}

🧐 Not the exact question you are looking for?Go ask a question

Solution

The appropriate return type for the getters and setters in the provided Java class would be as follows:

class Test{
    private int value;

    public void setValue(int value){
        //some code
        // This is a setter method which does not return anything. 
        // Hence, its return type is void.
    }

    public int getValue(){
        //some code
        // This is a getter method which should return the value of the private variable 'value'. 
        // Since 'value' is of type int, the return type of this method should also be int.
    }
}

This problem has been solved

Similar Questions

public class MyClass{private int value;public void setValue(int i){ / code / }// Other methods…}The method setValue assigns the value of i to the instance field value. What could you write for the implementation of setValue?Question 3Answera.value=iandthis.value = i;b.value = i; c.this.value = i;d.value == i;

Given the following set of classes:public class Customer { private String userName; private String password; public Customer(String userName, String password) { this.userName = userName; this.password = password; } public void setPassword(String password) { this.password = password; } public String getPassword() { return password; } public void setUserName(String userName) { this.userName = userName; } public String getUserName() { return userName; }} class CustomerTest { public static void main(String[] args) { Customer testAcct = new Customer("user","pass"); testAcct.setPassword("Java"); System.out.println(testAcct.toString()); }}What does the toString() method need to look like to result in the following output:UserName: userPassword: Javaa.)public String toString() { String state = "UserName: " + userName + "\n"; state += "Password: " + password + "\n"; return state;}b.)public String toString() { String state = "UserName: " + userName + "\n"; state += "Password: " + password + "\n"; return password;}c.)public String toString() { String state = "UserName: " + userName + "\n"; state = "Password: " + password + "\n"; return state;}d.)public String toString() { String state = "username: " + userName + "\n"; state += "password: " + password + "\n"; return state;}

Time left 0:09:44Question 3Not yet answeredMarked out of 1.00Flag questionQuestion textConsider the following class definition:public class MyClass{private int value;public void setValue(int i){ / code / }// Other methods…}The method setValue assigns the value of i to the instance field value. What could you write for the implementation of setValue?Question 3Answera.value=iandthis.value = i;b.value = i; c.this.value = i;d.value == i;

Demonstrate ability to set and change the values of object properties.Given the following class, what sets of statements would have the end result of the myCustomer instance having the username as XC1001 and the password as testpass?public class Customer { private String customerCode; private String password; public Customer(String customerCode, String password) { this.customerCode = customerCode; this.password = password; } public String getCustomerCode() { return customerCode; } public String getPassword() { return password; } public void setCustomerCode(String customerCode) { this.customerCode = customerCode; } public void setPassword(String password) { this.password = password; }}a.)Customer myCustomer = newCustomer("testpass","XC1001");b.)Customer myCustomer = new Customer("username","password");myCustomer.setCustomerCode("XC1001");myCustomer.setPassword("testpass");c.)Customer myCustomer = newCustomer("XC1001","testpass");myCustomer.setCustomerCode("user");myCustomer.setPassword("pass");d.)Customer myCustomer = new Customer();myCustomer.setCustomerCode("XC1001");myCustomer.setPassword("testpass");

public class Employee {    private String name;        public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public int getSal() {        return sal;    }    public void setSal(int sal) {        this.sal = sal;    }    private int sal;    public Employee(String name,int sal)    {        this.name = name;        this.sal = sal;    }    public String toString()    {        return name+" "+sal;    }    public int applyInc(int percentage)    {        return sal*percentage;    }}EmployeeStarter.java:public class EmployeeStarter {    public static void main(String[] args)     {        Employee employee = new Employee("Sangamithra",30000);  System.out.println(employee.applyInc(2));//calling the method of Employee that doubles the salary        System.out.println(employee.applyInc(e1->e1.getSal()*2));//line-1    }} How can the method, applyInc() of Employee class be redefined so that the functionality getting applied on Employee (doubling the salary) can be passed as an argument as in line-1? public int applyInc(Function<Employee, Integer> function) { return function.apply(this); }public int applyInc (Predicate<Employee> c) { return c.test(this); }public int applyInc (Consumer<Employee> c){ return c.accept(this); }Submit

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.