Custom Search

Monday, 27 August 2012

Java Program to illustrate Variable modifier like Public, Private, Protected, Java code to explain any three modifier


Java Program to illustrate Variable modifier like Public, Private, Protected, Java code to explain any three modifier


Program
class var
{
public int a;
final int b=24;
static int c;
private int d;
protected int e;

public void show()
{
System.out.println("Public:"+a);
System.out.println("Private:"+d);
System.out.println("Protected"+e);
System.out.println("Final:"+b);
System.out.println("Static:"+c);
}
}
class variablemodi
{
public static void main(String args[])
{
var v=new var();

v.a=10;
//v.d=20; bcoz it is private variable cant access outside the class
v.e=30;
//v.b=40; bcoz it is final variable so it is constant
var.c=50;
v.show();
}
}

No comments:

Post a Comment

Laptops