You are on page 1of 3

Lab 6:

Task 1: Implement the setter/getter functions using following code (Slide 11, lecture 5)

CODE:

public class Test {

int a ;

public int b;

private int c;

void setc(int i){

c=i;

int getc(){

return c;

public class AccesTest {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Test ob=new Test();

ob.a=10;

ob.b=20;

ob.setc(100);

System.out.println("a,b,c:"+ob.a+" "+ob.b+" "+ ob.getc()+" ");


}

Output:

Task2: Write a code that calls a static function in main (outside class) (reference Lecture 5)

CODE:

public class StaticDemo {

static int a = 42 ;

static int b = 99;

static void callme(){

System.out.println("a= "+a);

public class StaticByName {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

StaticDemo.callme();
System.out.println("b= " + StaticDemo.b);

OUTPUT:

You might also like