In the previous article, I explained the use of the Virtual & Override keywords. They are used for Method overriding concepts in polymorphism.
In this article, I am going to explain about the "New" modifier keyword. Let us see the below example first.
Programming Example 1 - without new modifier
Programming Example 1 - without new modifier
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace VirtualOverrideNew {
- class Circle {
- public void Area(double r) {
- Console.WriteLine(String.Format("Area of Circle : {0}", Math.PI * r * r));
- }
- }
- class Sphere: Circle {
- public void Area(double r) {
- Console.WriteLine(String.Format("Area of Circle : {0}", 4 * Math.PI * r * r));
- }
- }
- class Program {
- static void Main(string[] args) {
- Circle C = new Sphere();
- C.Area(4);
- }
- }
- }

Pankajkumar PatelPosted Sep 5, 2019, 12:17 AM
Good article
Bhavesh JadavPosted Mar 19, 2018, 11:39 PM
Nice one..........