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
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started