Java Quiz

peterlf (fromZtoA)
What output is produced by compiling and running the following program? Note that the instance variable named x is declared private (as highlighted in boldface in the code).

A. A compiler error
B. A runtime error
C. 15
class Q001_10{
public static void main(
String args[]){
AClass ref1 = new AClass(5);
AClass ref2 = new AClass(10);
}//end main()
}//end class definition

class AClass{
private int x;

AClass(int x){//constructor
this.x = x;
}// end constructor

int add(AClass ref){
return x + ref.x;
}//end add()

}//end class AClass

2000-10-10 -04:00

回到话题: Java Quiz

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论