Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Which of the following methods is from the Object class and often overridden? co

ID: 3788079 • Letter: W

Question

Which of the following methods is from the Object class and often overridden?

compareTo

remove

add

equals

size

All classes in Java inherit from the ______ class.

Class

Object

Parent

Static

Void

You have written a class called Frog and have not written a toString method.

Frog f = new Frog();
System.out.println(f);

What happens when the code above is executed?

Error - Frog has no toString method.

"Ribbit" is printed.

The toString method in Object is called.

Error - a class cannot be instantiated without the toString method.

Nothing happens.

What is output by the following code?

String [] w = {"zebra", "blaze"};
System.out.println(w[1].charAt(w[1].length() - 1));

a

b

e

r

z

You have written a class called Tree. In a second program you have the line:

Tree.getTemperature();

Which of the following must be true about the method getTemperature() for the method call to work?

getTemperature() must be void.

getTemperature() must be declared static.

getTemperature() must return a value.

getTemperature() must be declared private .

Nothing, this method call is not legal and will cause an error.

Questions 6-8 refer to the following class hierarchy:

Square extends Quadrilateral
Quadrilateral extends Polygon

Which of the following is true?

This class hierarchy will cause an error since Square can only have one parent class.

When a Square is instantiated the constructors in Quadrilateral and Polygon are not called.

Square has access to all methods and variables in Quadrilateral.

Square does not have access to any methods in Quadrilateral or Polygon.

Square has access to all public methods and variables in Quadrilateral.

Which of the following statements must be true in order for Square to access the constructor in Polygon?

Square has access to all public methods and variables in Polygon and will never need to directly call a constructor.

The call to Polygon's constructor must be the last line in Square's constructor.

The call to Polygon's constructor must be the first line in Square's constructor.

Square must first access Quadrilateral's constructor, and Quadrilateral's constructor must call Polygon's constructor.

Square's constructor must be declared private.

If a class Shape is added, which of the following would make the most sense?

Shape should be a child of Square.

Shape should be a child of Quadrilateral.

Shape should be a child of Polygon.

Polygon should be a child of Shape.

Shape should not be included in the hierarchy.

Write the header for the default constructor of a class called House.

public static House()

public int House()

public House(int numRooms, int floors)

public House()

public void House()

Which of the following is not true about a constructor?

It must have a void or return type.

It must have the same name as the class.

It should be declared public.

It initializes the instance variables of the class.

It must not have a void or return type.

Explanation / Answer

Please rate the solution give thumbs if this is helpful.

1:

Equals method is from the object class which is used to test whether an object is equal to another object.

2:

All classes in Java inherit from the object class. Object class is the super class in Java. All the classes must inherit from the Object class.

3:

The toString() method in Object is called. It is printing the object of the class Frog. Therefore, the toString() method of the class Frog is called.

4.

After executing the given code the output is shown below:

public class Character {

               public static void main(String[] args) {

               String [] w = {"zebra", "blaze"};

System.out.println(w[1].charAt(w[1].length() - 1));

}

The output is: e

5. The method getTemperature() must be declared static.

Explanation: This method is calling from another class. So, this method must be declared as static in the class Tree.

6. Square has access to all public methods and variables in Quadrilateral.

Explanation: Since, the Square extends the Quadrilateral, the Square can access to all public methods and variables in Quadrilateral.

7. If the Square has access to the constructor in Polygon, then it must access the Quadrilateral's constructor and the Quadrilateral's constructor must access the Polygons's constructors.

8.The Polygon must be child of the class Shape.

Explanation:

If the Class Shape is added, then the Polygon must be the chid of the class Shape because, the polygon has a shape. The class Shape must have the data variables like size, height, width. These data variables of the class Shape can be accessed the Polygon.

Therefore, The Polygon must be child of the class Shape.

9.The default constructor of the class Horse is given below:

public Horse(). It does not have void or any return type and does not have the arguments.

10. it must have void or any return type

Explanation:

The only statement, it must have void or any return type is not true about the default constructor. It must not have void or any return types. It must be declared as public.

The name of the default constructor must be same as the name of the class. It must initialize the instance variables of the class.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote