using instance constuctor we can intialize instance variable.
sample code:
public partial class EXPLAIN_PROGRAM_instance_variable : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
A a1 = new A(20);
A a2 = new A(30);
int r1 = a1.m();
Response.Write(r1);
}
}
public class A
{
public int x; //instance variable or global variable
public A(int x) //instance variable or instance method
{
this.x = x;
}
public int m() // instance method
{
return x;
}
}
{
protected void Page_Load(object sender, EventArgs e)
{
A a1 = new A(20);
A a2 = new A(30);
int r1 = a1.m();
Response.Write(r1);
}
}
public class A
{
public int x; //instance variable or global variable
public A(int x) //instance variable or instance method
{
this.x = x;
}
public int m() // instance method
{
return x;
}
}
No comments:
Post a Comment