Find the error in each of the following code segments: // Superclass public clas
ID: 3534107 • Letter: F
Question
Find the error in each of the following code segments:
// Superclass
public class Vehicle
{
( Member declarations . . .)
}
// Subclass
public class Car expands Vehicle
{
( Member declarations . . .)
}
Describe errors with a couple of sentences of words.
Find the error in each of the following code segments:
// Superclass
public class Vehicle
{
private double cost;
( Other methods . . .)
}
// Subclass
public class Car extends Vehicle
{
public Car( double c)
{
cost = c;
}
}
Describe errors with a couple of sentences of words.
Find the error in each of the following code segments:
// Superclass
public class Vehicle
{
private double cost;
public Vehicle( double c)
{
cost = c;
}
( Other methods . . .)
}
// Subclass
public class Car extends Vehicle
{
private int passengers;
public Car( int p)
{
passengers = c;
}
( Other methods . . .)
}
Describe errors with a couple of sentences of words.
Explanation / Answer
1.
public class Car expands Vehicle it should be extends
{
( Member declarations . . .)
}
2.
public class Car extends Vehicle
{
public Car( double c)
{
cost = c; // cost is private variable of super class which can not be used in subclass
}
}
3.
public class Car extends Vehicle
{
private int passengers;
public Car( int p)
{
passengers = c; // c is an undeclraed variable in class Car
}
( Other methods . . .)
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.