aaaaaaaaaaaaaaaaa
public | A base class's public members are accessible anywhere that the program has a reference
to an object of that base class or one of its derived classes. |
---|---|
protected | protected access offers an intermediate level of protection between public and
private access, A base class's protected members can be accessed only in that base class or
in any classes derived from that base class. |
private | A base class's private members are accessible only within the body of that base class. |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
public class Program
{
public class c1 //if U not write here 'public' then no problem
{ //it is Ur choice.
public void fun() //If U not write here 'public'then not working
{ //bcz it is not accessable from outside the class.
Console.WriteLine("This is 1st class");
}
}
public class c2 //this is class 'c2'.
{
public void fun2() //public is must.
{
Console.WriteLine("This is 2nd class");
}
}
static void Main(string[] args)
{
c1 c = new c1(); //'c' is object of 'c1' class.
c2 cc = new c2(); //and 'cc' is object of 'c2' class.
c.fun(); //calling 'fun' function of class 'c1' with
cc.fun2(); //the help of 'c' object.
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
public class Program
{
static void Main(string[] args)
{
c1 c = new c1(); //'c' is object of 'c1' class.
c2 cc = new c2(); //and 'cc' is object of 'c2' class.
c.fun(); //calling 'fun' function of class 'c1' with
cc.fun2(); //the help of 'c' object.
Console.ReadLine();
} //I call 1st 'fun();' of 'c1' class and 2nd call 'fun2();'
} //of 'c2' class,If U wish U call 1st 'fun2();' of 'c2' class and
//2nd call 'fun();' of 'c1' class, it is Ur choice.
public class c1 //if U not write here 'public' then no problem
{ //it is Ur choice.
public void fun() //If U not write here 'public'then not working
{ //bcz it is not accessible from outside the class.
Console.WriteLine("This is 1st class");
}
}
public class c2 //this is class 'c2'.
{
public void fun2() //public is must.
{
Console.WriteLine("This is 2nd class");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
public class c1
{
public void fun()
{
Console.WriteLine("This is 1st class");
}
}
public class c2 //this is class 'c2'.
{
public void fun2() //public is must here.
{
Console.WriteLine("This is 2nd class");
}
}
public class c3 //this is class 'c3'.
{
public void fun3() //public is must here.
{
Console.WriteLine("This is 3rd class");
}
static void Main(string[] args)
{
c1 c = new c1(); //'c' is object of 'c1' class.
c2 cc = new c2(); //and 'cc' is object of 'c2' class.
c3 bi = new c3(); //and 'bi' is object of 'c3' class.
c.fun();
bi.fun3();
cc.fun2();
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
public class Program
{
public class c1
{
public string firstname = "HiLaLs";
public string lastname = "Afridi";
}
public class c2
{
public string fathername = "M'Aslam";
public string address = "Dara";
}
static void Main(string[] args)
{
c1 c = new c1();
c2 cc = new c2();
Console.WriteLine(c.firstname);
Console.WriteLine(c.lastname);
Console.WriteLine(cc.fathername);
Console.WriteLine(cc.address);
Console.ReadLine();
}
}
}