Why is the value of 'Z' IS '
0 '
?
code show as below:
Public class intadder {
Private int x;
PRIVATE INT Y;
Private int Z;
Public void intadder () {
X = 100;
y = 200;
z = x y;
}
Public void printresults () {
System.out.println ("The value of 'z' is'" z "");
}
Public static void main (String [] args) {
INTADDER IA = New INTADDER ();
Ia.printResults ();
}
}
Why didn't you output that result? This is actually because adding Void, it is not this type of constructor. Many people are confused by it, this is just the same method as class name, this class is actually called The default constructor "Intadder ()", so the value of x, y is 0, and Z is also 0. When there is no write constructor, create an object will call the default constructor, that is, there is no parameters. Empty function.