C# For this programming question: Create a program that has two classes: ClassA
ID: 3717125 • Letter: C
Question
C#
For this programming question: Create a program that has two classes: ClassA and ClassB (0.25 marks) ClassA will . extend ClassB (0.5 marks) have a private field called link that will be of type ClassA (0.5 marks) have a set and get property that will set and return the private field (0.5 marks) ClassB will have a public method called Calculate (0.25 marks) .This method will take in 2 integers as parameters (0.5 marks) This method will return an integer. The return value will be the product (multiplication) of the two values. (0.5 marks) In the main function . instantiate a variable of classA (0.25 marks) . have this variable calculate 12 and 3 (0.25 marks) print out the result of the variable calculation (0.25 marks) Submit the solution files as a compressed file. (0.25 marks)Explanation / Answer
Below is your code
using System;
//declaration of namespace containing classes
namespace ClassInheritence {
//declarationof classA extending ClassB
class ClassA : ClassB {
//private variable link and its getter and setter
private ClassA link { get; set; }
}
//declarationof ClassB
class ClassB {
//method to Calculate Product
public int Calculate(int a, int b) {
return a*b;
}
}
//main class to run the program
class MainClass {
//main method with instructions
public static void Main (string[] args) {
//ClassA object instantiation
ClassA aObject = new ClassA();
//calculating profuct and displaying result
int prod = aObject.Calculate(12,3);
Console.WriteLine ("Product of two numbers is {0}",prod);
}
}
}
Output
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.