Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c sharp, Create a class named SquareClass having the following members: An in

ID: 3585999 • Letter: I

Question

In c sharp, Create a class named SquareClass having the following members: An instance attribute named side, which defaults to 10. - One instance constructor that initializes the attribute side when an instance is created. Two methods below: MethodA is an instance method that can only be accessed inside of the class Square. It calculates the area of a square. -MethodB is an instance method that can be accessed from another class. It calculates the perimeter of a square. Write a class named TestSquareClass to call each method in the class SquareClass if it can be accessed in the class TestSquareClass .

Explanation / Answer

using System.IO;

using System;

public class SquareClass

{

int side = 10;

public int Side

{

get { return side; }

set { side = value; }

}

public SquareClass() {

side = 10;

}

public SquareClass(int side) {

Side = side;

}

private double MethodA() {

return side * side;

}

public double MethodB() {

return 4 * side;

}

}

class TestSquareClass

{

static void Main()

{

SquareClass s = new SquareClass(5);

Console.WriteLine("Perimeter: "+s.MethodB());

//Console.WriteLine("Area: "+s.MethodA());

}

}

Output:

MethodA is not accessible because it have private access specifier it means it can only accessable with in the same class..

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote