Question: public class Road { private String roadName; public Road(String name) { roadName = name; } } public class Highway extends Road { private int speedLimit;
public class Road
{
private String roadName;
public Road(String name)
{
roadName = name;
}
}
public class Highway extends Road
{
private int speedLimit;
public Highway(String name, int limit)
{
super(name);
speedLimit = limit;
}
}
The following code segment appears in a method in another class.
Road r1 = new Highway("Interstate 101", 55); // line 1
Road r2 = new Road("Elm Street"); // line 2
Highway r3 = new Road("Sullivan Street"); // line 3
Highway r4 = new Highway("New Jersey Turnpike", 65); // line 4
Which of the following best explains the error, if any, in the code segment?
-
A) Line 1 will cause an error because a Road variable cannot be instantiated as an object of type Highway.
-
B) Line 2 will cause an error because the Road constructor is not properly called.
-
C) Line 3 will cause an error because a Highway variable cannot be instantiated as an object of type Road.
-
D) Line 4 will cause an error because the Highway constructor is not properly called.
-
E) The code segment compiles and runs without error.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
