Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6692033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:49:15+00:00 2026-05-26T05:49:15+00:00

hej guys, I am trying to solve this homework. I have reached a dead

  • 0

hej guys,

I am trying to solve this homework. I have reached a dead end and I am looking for someone who could help with this issue.

This is the task I am trying to solve:

Work 2: An abstract class is not a complete class, it misses some
parts, and you cannot create objects from it. The programmer who
writes the derived classes must fill in the missing parts. Consider
an abstract class Vehicle. Derive two hierarchies from this class as
it is shown below: Now, write 4 classes, see the yellow rectangle.
Start from the abstract base class Vehicle -> Vehicle with 4 wheels
-> Sport Cars and stop at the derived class Rally, which is the most specific class. The class Vehicle contains a field which
holds the vehicle name and an abstract method void Display().

Implement this function in the derived classes, so that the function
returns information about the vehicle, e.g. the motor power and other
necessary properties. The last derived class has private fields to
hold the motor power, the car weight, the car acceleration, the
highest speed and a function that computes the specific power (power
/ weight). The function Display returns a text string with all this
information. Test your work in a Console application that uses
objects of the type of the classes Sport car and Rally.

Class Vehicle:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A_work_2
{
public abstract class Vehicle
{
    public string vehicleName;
    public abstract void Display();

}
}

Class Vehicle4Wheels:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A_work_2
{
public class Vehicle4Wheels : Vehicle
{
    public override void Display() 
    {
        Console.WriteLine("Car with four wheels.");
    }
}
}

Class SportCar:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A_work_2
{
public class SportCar : Vehicle4Wheels {
    public override void Display()
    {
        Console.WriteLine("Sport version of the car.");
    }
}
}

Class Rally:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A_work_2
{
public class Rally : SportCar
{
private double motorPower = 408;
private double carWeight = 2380;
private double carAcceleration = 4.7;
private double highestSpeed = 250;

public double SpecificPower()
{
    double specificPower = motorPower / carWeight;
    return specificPower;
}

public override void Display()
{

   Console.WriteLine("The acceleration is: {0}.\nThe highest speed is {1} km/h.", carAcceleration, highestSpeed);
   Console.WriteLine("Specific power is {0}", SpecificPower());


}
}
}

I am not sure if I understand the task clearly and with the code I have so far, I dont know if I am on the right way to make it happen. I dont understand abstract classes and inhertiance very much.

Thank you for your help!

V.

EDIT: My question is: How can I change the code I have written to fulfill the task I have been given? Because I am not sure how to be general while writing the code. When I add car attribute to the Vehicle4Wheels class like:

private double carWeight;

How can I then approach this attribute in later derived classes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:49:15+00:00Added an answer on May 26, 2026 at 5:49 am

    I am not sure if I understand the task clearly and with the code I have so far, I dont know if I am on the right way to make it happen

    So, lets review what you’ve got so far…

    When I add car attribute to the Vehicle4Wheels class like:
    private double carWeight;
    How can I then approach this attribute in later derived classes?

    Your homework assignment didn’t tell you to worry about that.

    “The last derived class has private fields to hold the motor power, the car weight, the car acceleration, the highest speed and a function that computes the specific power (power / weight)”

    You’ve implemented this pretty well already. The part you are missing is this:

    “Test your work in a Console application that uses objects of the type of the classes Sport car and Rally.”

    Once you’ve implemented this, you’ll understand the point of all the code you’ve written.

    To make it interesting, and so you get the point of the exercise, make sure your console app does something like this:

    Vehicle sportCar = new SportCar();
    sportCar.Display();
    
    Vehicle rally = new Rally();
    rally.Display();
    

    Notice I didn’t say Rally rally = new Rally();

    Also notice that Vehicle something = new SportsCar(); works. Try adding a line: Vehicle something = new Vehicle(); – It won’t compile.

    This all will demonstrate some of the most important parts of inheritance and (abstract) base types:

    • You can interact with a base type and get derived behavior
    • You can’t create instances of abstract types directly, but you can still use those types in your code

    Try this all and see what happens.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code, int main() { std::string st; std::stringstream ss; ss<<hej hej med
Hej, assuming I have a code that looks like this: List<User> userList = GetUserByName
Hej everyone, problem : I am looking for right way to convert an index
Hej folks, I'm currently completely stuck with the following and don't even have the
Hej I am trying to load an (embedded) image in a wpf application, using
Hej! I am looking for a portable way of periodically dispatching a task in
This my method in my repository: public List<Question> getallquestion() { var hej = from
I have a simple question, how to convert this server into multithreded as far
Hej! Caution this is a long post -- if you are easily annoyed better
I have an array like this, which I json encode: $regularArray = array( array(

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.