Ask Question
21 February, 02:49

Write a class named Add that has the following data members, constructor, and methods:

Data Members:

private int row; / / The number of rows for the addition table.

private int column; / / The number of columns for the addition table.

Constructor:

/ / Sets the values of the above data members.

public Add ()

Methods:

+5
Answers (1)
  1. 21 February, 03:25
    0
    A class is like a blueprint of object.

    Explanation:

    A class defines the kinds of data and the functionality their objects will have.

    A class enables you to create your own custom types by grouping together variables of other types, methods and events.

    In C#, we can create a class using the class keyword.

    Here's a sample program:

    using System;

    namespace ConsoleApplication

    {

    public class Test

    {

    public static void Main ()

    {

    Add a1 = new Add (70, 50);

    a1. AddNumbers ();

    Console. ReadLine ();

    }

    }

    class Add

    {

    private int row;

    private int column;

    public Add (int r, int c)

    {

    row = r;

    column = c;

    }

    public void AddNumbers ()

    {

    Console. WriteLine (row+column);

    }

    }

    }

    output: 120

    Explanation of the program:

    I have created a class named Add. Within a class, row and column are two fields and AddNumbers () is a method. We also have constructor to initialize row and column.

    In main method, If I need to invoke members of the class, I must create an instance of the class. We can create any number of instances using the single class. IN our program, a1 is the reference variable using which we can invoke members of the class. I invoked function in the class and passed arguments to the constructor while creating an instance.

    Those values are assigned to method variables and it operated the addition. Thus the output is 120.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a class named Add that has the following data members, constructor, and methods: Data Members: private int row; / / The number of ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers