Question

What is Multiple Inheritance and explain it using a Class Diagram and Write a Code for...

What is Multiple Inheritance and explain it using a Class Diagram and Write a Code for it in C#. Use Set() and Get() as well.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C# code


/**
* Multiple inheritance is a concept, When a child class inherits more than one
* class means it has more than one super class is known as multiple inheritance.
* Since as we know Multiple inheritance is not supported by c# due to conflict.
* So to acquire this phenomenon we use Interfaces.
* Interfaces is one which contains pure abstract methods.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace multiple_inheritance
{
interface Car
{
void speed();
}
interface CarPolicy
{
bool policyStatus();
}
class Driver : Car, CarPolicy
{
private String vehicleType;
private bool isPolicyActive;
//getter and setters property
public String VehicleType
{
get
{
return vehicleType;
}
set
{
vehicleType = value;
}
}
public bool IsPolicyActive
{
get
{
return isPolicyActive;
}
set
{
isPolicyActive = value;
}
}
public void speed()
{
Console.WriteLine(vehicleType+" is running at average speed.");
}
public bool policyStatus()
{
return isPolicyActive;
}
  
}
class Program
{
static void Main(string[] args)
{
Driver d1 = new Driver();
d1.VehicleType = "Car";
d1.IsPolicyActive = true;
if(d1.policyStatus())
{
Console.WriteLine("Car policy is active. ");
}
else
{
Console.WriteLine("Car policy is not active.");
}
d1.speed();
//pause
Console.ReadLine();
}
}
}


//output

//Class diagram

//If you need any help regarding this solution... please leave a comment...... thanks

Add a comment
Know the answer?
Add Answer to:
What is Multiple Inheritance and explain it using a Class Diagram and Write a Code for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USE C++ Demonstrate how to write an interface for a VEHICLE class using C++. In your...

    USE C++ Demonstrate how to write an interface for a VEHICLE class using C++. In your interface, demonstrate the following (use comments to explain or for demonstration): -Interface implementation -Multiple interface implementation for a single class -Example of a Diamond Inheritance problem -Polymorphism Explain each term above clearly in the code example and discuss how it is being used USE C++

  • UML Class Diagram with Inheritance Objectives Use UML Correctly indicate inheritance Demonstrate permissions Understand inheritance relationships...

    UML Class Diagram with Inheritance Objectives Use UML Correctly indicate inheritance Demonstrate permissions Understand inheritance relationships Labwork Please read all of the directions carefully. You will create a UML class diagram reflecting the class hierarchy for a fictional program that manages university personnel as constructed according to the graph displayed below. You will need to think about the attributes and behaviors that are unique to each class, and also those attributes and behaviors that are common amongst the subclasses and...

  • Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance...

    Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance variables x and y that represented for the coordinates for a point. Provide constructor for initialising two instance variables. Provide set and get methods for each instance variable, Provide toString method to return formatted string for a point coordinates. 2. Create class Circle, its inheritance from Point. Provide a integer private radius instance variable. Provide constructor to initialise the center coordinates and radius for...

  • i need the same code but using inheritance and abstract class at least build a super...

    i need the same code but using inheritance and abstract class at least build a super abstract class , a sub class and build a main to run the code with javafx JOptionpane please if you can not answer the write code don't answer (Thank you) import javax.swing.JOptionPane; public class CollegeAdmission{ public static void main(String args[]) { String testScoreString; String classRankString; int testScore; int classRank; testScoreString = JOptionPane.showInputDialog("Enter test score: "); testScore = Integer.parseInt(testScoreString); classRankString = JOptionPane.showInputDialog("Enter class rank: ");...

  • 1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class...

    1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class Student and class ComputerSystemsStudent which are described below. Make sure to show all the members (member variables and member functions) of the classes on your UML diagram. Save your UML diagram and also export it as a PNG. B) Second, write a program that contains the following parts. Write each class interface and implementation, in a different .h and .cpp file, respectively. a) Create...

  • Need help with a multiple inheritance work Question Compile and run the file. If you find...

    Need help with a multiple inheritance work Question Compile and run the file. If you find any compilation errors,explain their reason as comments in the code. Then fix the errors such that the program compiles and runs. Explain the motivation of your modifications in the code and their effects on the execution inheritance.cpp file #include<iostream> using namespace std; class A { int x; public: void setX(int i) {x = i;} void print() { cout << x; } }; class B:...

  • Create a class named Game using the following UML class diagram. GAME -gameName : string +Game()...

    Create a class named Game using the following UML class diagram. GAME -gameName : string +Game() +setGameName(in name : string) : void +getGameName() : string +displayMessage() : void This class has 2 member variables namely playerName and playerScore. The class contain following member functions: Constructor, set function, get functions, display function. Code write in 3 files: Game.h header file, funtion.cpp file and main.cpp file. The output should be: Player John has scored 50 points.

  • (15)Given the following classes, how would you arrange them in an inheritance hierarchy? class Pen; class...

    (15)Given the following classes, how would you arrange them in an inheritance hierarchy? class Pen; class BallPoint; class Pencil; class MechnicalPencil; class WoodPencil; class WritingInstrument; class FountainPen; Draw the inheritance diagram and relate the classes via C++ code.

  • Please write below code in C++ using Visual Studio. Write program that uses a class template...

    Please write below code in C++ using Visual Studio. Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 • Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the...

  • What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that...

    What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that derives from a superclas:s ■ Demon "Declare a variable of the superclass type and assign it an instance of the subclass type strate polymorphic behavior Access the public members of the superclass type Notice how the overridden versions of the subclass type are called Notice how the subclass specific members are inaccessible "Create an array of superclass type and use a foreach loop to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT