Question

Consider the following code snippet: Employee programmer = new Employee(10254, "exempt"); String str = programmer.toString(); Assume...

Consider the following code snippet:

Employee programmer = new Employee(10254, "exempt");
String str = programmer.toString();

Assume that the Employee class has not implemented its own toString() method. What value will the variable str contain when this code is executed?

Group of answer choices

the variable will become a null reference

the code will not compile because Employee has not implemented toString()

the default from Object, which is the class name of the object and its hash code

the string representations of all of the field values

2

With very few exceptions, such as certain static constants, what access should fields of classes always have?

Group of answer choices

package

protected

public

private

3

How can a subclass modify a private field within its superclass?

Group of answer choices

use "super." followed by the name of the field

use a public method of the superclass

override the field with a field of the same name

use the name of the superclass field

4

Which is the difference between having a public field, and having a private field with public getter/setter methods?

Group of answer choices

there is effectively no difference between these approaches

getter/setter methods can be inherited, while fields cannot

setters can reject invalid values, and getters can do processing of the output

fields can be inherited, whereas getter/setter methods cannot

Homework Answers

Answer #1

ANSWERS -

1) (c) the default from Object, which is the class name of the object and its hash code

The variable str will contain the object name along with its hash code when this code is executed.

2) (c) Public

Most of the time classes should also have Public declared.

3) (b) use a public method of the superclass

A subclass can modify a private field by using public method within its superclass.

4) (c) setters can reject invalid values, and getters can do processing of the output

Setters and getters to make write only or read only, it can also make sure that correct value is being set by placing some validations in setters and getters.

=================================END================================

Please comment if u need any other info and DO LEAVE A LIKE, it would mean a lot. Thanks :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the following code snippet: // A.java public class A { private String name; protected A(String...
Consider the following code snippet: // A.java public class A { private String name; protected A(String n) { name = n; } } // B.java public class B extends A { public B(String n) { super(n); } public String toString() { return name; } } What's wrong with the above code? Select all that apply. This code will encounter an access error at runtime. This code will not compile, because A's constructor is not declared public. This code will not...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){    strName = " ";    strSalary = "$0";    } public Employee(String Name, String Salary){    strName = Name;    strSalary = Salary;    } public void setName(String Name){    strName = Name;    } public void setSalary(String Salary){    strSalary = Salary;    } public String getName(){    return strName;    } public String getSalary(){    return strSalary;    } public String...
Which statement is not true? Question 10 options: A subclass can add its own fields and...
Which statement is not true? Question 10 options: A subclass can add its own fields and methods. A subclass is more specific than its superclass The subclass exhibits the behaviors of its superclass and can only add upon behaviors that are defined in the superclass. Every subclass object is an object of its superclass. Interfaces are particularly used for ______. Question 8 options: polymorphysim. programming in general. assigning common functionality to possibly unrelated classes. assigning common functionality to similar classes....
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its variables (firstName and lastName). It should contain an abstract method called payPrint. Below is the source code for the Employee9C superclass: public class Employee9C {    //declaring instance variables private String firstName; private String lastName; //declaring & initializing static int variable to keep running total of the number of paychecks calculated static int counter = 0;    //constructor to set instance variables public Employee9C(String...
java Considering the following code segment, answer the multiple choice questions. public String foo(String input) {...
java Considering the following code segment, answer the multiple choice questions. public String foo(String input) { String str = input.toLowerCase(); return bar(str); } private String bar(String s) { if (s.length() <= 1)   {return "";} else if (s.length() % 2 == 0)   {return "*" + bar(s.substring(2, s.length()));} else if (s.length() % 2 == 1) {return "*" + bar(s+"n");} else {return "";} } Which line(s) indicate the name of the helper method? Which line(s) contains recursive call(s)? How many * are in...
QUESTION 1: This question is also to be used for the next question. Design an Employee...
QUESTION 1: This question is also to be used for the next question. Design an Employee class for a hotel for use in programs. We need an Employee object with these attributes: Name Designation (ex. Manager, Supervisor, Waiter, Bellhop, etc.) ID number Some details: ID Numbers should already be known at time of object's creation. Assume it is an 8 digit number. The ID Number can never be changed Use strings to represent the Name and Designation It is possible...
C++ 5a)We have the following class: class Banana { private:      string s;      int y;...
C++ 5a)We have the following class: class Banana { private:      string s;      int y; public: bool theMemberFunc (string); void setterForS(string); // setter for s string getterForS(); // getter for s }; Instantiate a static object of Banana named co. a)int Banana; b)co.Banana = new; c)Banana = new class; d)Banana co; 5b)Code a call to function aNonclassFunction passing co. a)aNonclassFunction (co); b)aNonclassFunction (* co); c)aNonclassFunction (aGoodClass.co); d)aNonclassFunction (aGoodClass); 5c)Code the function definition for aNonclassFunction, picking up co. aNonclassFunction has...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character for the first word and uppercase for every other word - classes start with an uppercase character of every word - packages use only lowercase characters - methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228 Exercise #1: [5 marks] Write a Java application using...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments,...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments, hands-on labs, discussions, and assignments to date. Create a Java class named HeadPhone to represent a headphone set. The class contains:  Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.  A private int data field named volume that specifies the volume of the headphone. The default volume is MEDIUM.  A private...