protected internal is a keyword and access modifier also. We use this keyword for restricted unwanted data using out of assembly and inherit classes.
Firstly we have to know that when we use an internal access modifier that means we can use those methods the same assembly or out of the assembly and when we use protected that means we can use those methods in any other inherited class.
Now when we use both access modifiers(protected internal) then we can use those methods out of assembly and inherited class also.
Some important things about protected internal access modifier: -
- We can use protected internal access modifier's the same assembly or out of the assembly without inherited class by creating an object of the base class.
- We can use protected internal access modifier's the same assembly or out of the assembly in the derived class by creating an object of the derived class.
- We can also use this access modifier's method by using the base keyword in the derived class. Syntax: - base.<method name>();
We can also use this access modifier method by using this keyword the derived class. Syntax: - this.<method name>();
Code: -(Without inherited class)
using System;
namespace HelloGeeksApp
{
class profile
{
protected internal string name;
public void print(string a)
{
string name= a;
Console.WriteLine("\nMy name is " + name);
}
}
class Program
{
static void Main(string[] args)
{
profile ac = new profile();
ac.name = Console.ReadLine();
ac.print("Om Ji Mishra ");
Console.ReadLine();
}
}
Output: - My name is Om Ji Mishra
Code: - (With inherited class)
using System;
namespace HelloGeeksApp
{
class profile
{
protected internal string name;
public void print(string a)
{
string name= a;
Console.WriteLine("\nMy name is " + name);
}
}
class sau: profile
{
static void Main(string[] args)
{
sau ac = new sau();
ac.name = Console.ReadLine();
ac.print("Om Ji Mishra ");
Console.ReadLine();
}
}
}
Output: - My name is Om Ji Mishra
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
protected internal is a keyword and access modifier also. We use this keyword for restricted unwanted data using out of assembly and inherit classes.
Firstly we have to know that when we use an internal access modifier that means we can use those methods the same assembly or out of the assembly and when we use protected that means we can use those methods in any other inherited class.
Now when we use both access modifiers(protected internal) then we can use those methods out of assembly and inherited class also.
Some important things about protected internal access modifier: -
or out of the assembly in the derived class by creating an object of the derived class.
keyword in the derived class.
Syntax: - base.<method name>();
keyword the derived class.
Syntax: - this.<method name>();
Code: -(Without inherited class)
Output: - My name is Om Ji Mishra
Code: - (With inherited class)
using System;
Output: - My name is Om Ji Mishra