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
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....
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...
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...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
Design a Java class named Polygon that contains:  A private int data field named numSides...
Design a Java class named Polygon that contains:  A private int data field named numSides that defines the number of sides of the polygon. The default value should be 4.  A private double data field named sideLength that defines the length of each side. The default value should be 5.0.  A private double data field named xCoord that defines the x-coordinate of the center of the polygon. The default value should be 0.0.  A private double...
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a...
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a sub class's constructor? Select one: a. It must be the first statement in the constructor b. If you don't include it Java will c. If you don't include it you must have a 0 parameter constructor coded in the super class or no constructors coded at all in the super class d. The sub class constructor containing the super call and the called super...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT