Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Shape {
- protected int length;
- public Shape() { //default constructor
- Console.WriteLine("Shape's default constructor");
- }
- public Shape(int length) { //constructor with parameters
- this.length = length;
- Console.WriteLine("Shape's constructor with 1 parameter");
- Console.WriteLine(this.length);
- }
- }
- class Square: Shape {
- public Square(): base() { //calling Shape class default constructor using base
- Console.WriteLine("Square's default constructor");
- }
- public Square(int length): base(length) { //calling Shape class constructor with parameters using base
- Console.WriteLine("Sqaure's constructor with 1 parameter");
- Console.WriteLine(this.length);
- }
- public int get_Area(){ return (length * length); } //method computing area of square
- }
- class Program {
- static void Main() {
- Square sq1 = new Square(); //making object of child class Sqaure
- Square sq2 = new Square(5); //setting length equal to 5
- Console.WriteLine("Area of sq1 is: {0}",sq1.get_Area());
- Console.WriteLine("Area of sq2 is: {0}",sq2.get_Area());
- }
- }
Add Comment
Please, Sign In to add comment