×

Loading...

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
//File Q001_10.java
class Q001_10{
public static void main(
String args[]){
AClass ref1 = new AClass(5);
AClass ref2 = new AClass(10);
System.out.println(
ref1.add(ref2));
}//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
(#10371@0)
2000-10-10 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: Java Quiz

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论