
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Equivalent of Java Super Keyword in C#
For super keyword in Java, we have the base keyword in C#.
Super keyword in Java refers immediate parent class instance. It is used to differentiate the members of superclass from the members of subclass, if they have same names. It is used to invoke the superclass constructor from subclass.
C# base keyword is used to access the constructors and methods of base class. Use it within instance method, constructor, etc.
Let us see an example of C# base.
Example
using System; public class Animal { public string repColor = "brown"; } public class Reptile: Animal { string repColor = "green"; public void display() { Console.WriteLine("Color: "+base.repColor); Console.WriteLine("Color: "+repColor); } } public class Demo { public static void Main() { Reptile rep = new Reptile(); rep.display(); } }
Output
Color: brown Color: green
Advertisements