Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- // Base class
- class Shape {
- public Shape(){length = 0;} //default constructor
- public void setlength(int l) {length = l;}
- protected int length;
- }
- // Derived class
- class Sqaure: Shape {
- public Sqaure() {length = 0;} //declaring and initializing derived class constructor
- public int get_Area(){ return (length * length); }
- }
- class Program
- {
- static void Main(){
- Sqaure sq = new Sqaure(); //making object of child class Sqaure
- sq.setlength(5); //setting length equal to 5
- // Print the area of the object.
- Console.WriteLine("Total area of sqaure is: {0}",sq.get_Area());
- }
- }
Add Comment
Please, Sign In to add comment