You are on page 1of 1

Assignment 2

Using static variables, static methods, static blocks, create a java program and
display the results. Using “this” word get data and display the results.

package static1;

public class Static {


static int n;
static String str;

public Static(int n, String str)


{
this.n=n;
this.str=str;
}

static
{
System.out.println("Static block ");
n=88;
str= "Block";
}

static void display()


{
System.out.println("n is = "+n);
System.out.println("str is = "+str);
}

public static void main(String[] args) {


display();
}

Output:

Static block
n is = 88
str is = Block

You might also like