Friday, 10 May 2013

Constructor - 2 -

What will happen when you attempt to compile and run the following code?


package net.dharmaraj;

public class Sandys {

public int court = 100;

public static void main(String argv[]) {


Sandys s = new Sandys(99);

System.out.println(s.court);
}

Sandys(int ballcount) {

court = ballcount;
}
}





1) Compile time error, the variable court is defined as private
2) Compile time error, s is not initialized when the System.out method is called
3) Compilation and execution with no output
4) Compilation and run with an output of 99

No comments:

Post a Comment