Week 1 Assignment Q1 Solution

324 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
324
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Week 1 Assignment Q1 Solution

  1. 1. public class Parent{ string parentString; public Parent() { Console.WriteLine("Parent Constructor."); } public Parent(string myString) { parentString = myString; Console.WriteLine(parentString); } public void print() { Console.WriteLine("Im a Parent Class."); }}public class Child : Parent{ public Child() : base("From Derived") { Console.WriteLine("Child Constructor."); } public new void print() { base.print(); Console.WriteLine("Im a Child Class."); }
  2. 2. static void Main(string[] args) { Child child = new Child(); child.print(); ((Parent)child).print(); }}

×