Question

The Object class is expanded by all classes, and all classes inherit the String and Equals...

The Object class is expanded by all classes, and all classes inherit the String and Equals methods. Explain why we should override the two strategies at all times.

Homework Answers

Answer #1

the toString() and equals() methods are the methods of Object class, since all classes inherit these methods, but on using such methods we get some different results this is because when we use toString() method of Object class then it convert the details of object (class name and address) into the string similarly when we use equals() method of Object class then the reference of the objects will be compared not their values, therefore in order to get the object details we need to override the toString() method of object class in the child class, and similarly in order to use the logical equality (instead of reference equality) we need to override the equals() method in the child class.

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
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all...
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all four classes. Shape2D class For this class, include just an abstract method name get2DArea() that returns a double. Rectangle2D class Make this class inherit from the Shape2D class. Have it store a length and a width as fields. Provide a constructor that takes two double arguments and uses them to set the fields. Note, the area of a rectangle is the length times the...
Practice manipulating an object by calling its methods. Complete the class Homework1 class using String methods....
Practice manipulating an object by calling its methods. Complete the class Homework1 class using String methods. Remember that all the String methods are accessors. They do not change the original String. If you want to apply multiple methods to a String, you will need to save the return value in a variable. Complete the class by doing the following: + Print the word in lowercase + Replace "e" with "3" (Use the unmodified variable word) + Print the changed word...
The sum of the relative frequencies for all classes in a histogram always equals a. the...
The sum of the relative frequencies for all classes in a histogram always equals a. the total of all the frequencies. b. the number of classes. c. one. d. none of these answers are correct.. e. the class width.
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1...
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1 = new String("hello"); String s2 = "hello"; String s3 = "hello";    System.out.println(s1 == s3); System.out.println(s1.equals(s3)); System.out.println(s2 == s3); } } When we run the program, the output is: false true true Explain why this is the output, using words and/or pictures.
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals Create the client for testing the Student class (5 points extra credit) Create another class called CourseSection (20 points extra credit) Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student) Create all of...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String),...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String), Monthly Salary (double)). Create a constructor that initializes these variables. Define set and get methods for each variable. If the monthly salary is not positive, do not set the salary. Create a separate test class called EmployeeTest that will use the Employee class. By running this class, create two employees (Employee object) and print the annual salary of each employee (object). Then set the...
Java Programming In this lab students continue to write programs using multiple classes. By the end...
Java Programming In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to Write classes that use arrays and ArrayLists of objects as instance variables Write methods that process arrays and ArrayLists of objects Write getter and setter methods for instance variables Write methods using object parameters and primitive types Question- class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these...
The String Class: 1a.) Given the following delcaration: String modification1; Write a statement that stores the...
The String Class: 1a.) Given the following delcaration: String modification1; Write a statement that stores the uppercase equivalent of the string object called "city" in modification1. 1b.) Write a statement that declares a String variable named city. The variable should be initialized with the string literal "Los Angeles". 1c.) Given the following declaration: int stringSize; Write a statement that stores the length of the string object called "city" in stringSize. 1d.) Given the following declaration: char oneChar; Write a statement...
We tested the memorability of the following two strings in our class: String A: BCSBMIUBS String...
We tested the memorability of the following two strings in our class: String A: BCSBMIUBS String B: CBSIBMSBU It turned out that string B is easier to memorize than String A. True / False Explain:
This is my course class. Can someone please explain what the equals method is for and...
This is my course class. Can someone please explain what the equals method is for and also the compareTo method is for in general and then explain what the methods are doing in this class. public class Course {    private boolean isGraduateCourse;    private int courseNum;    private String courseDept;    private int numCredits;       public Course(boolean isGraduateCourse, int courseNum, String courseDept, int numCredits) {        this.isGraduateCourse=isGraduateCourse;        this.courseNum=courseNum;        this.courseDept=courseDept;        this.numCredits=numCredits;   ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT