Hello fellow coders, newbie here!
Here’s my problem, I made a class other than my Main class and named it “Second” and you can see the codes I wrote down below:
package com.company;
public class Second {
public int x;
public int y;
public int a;
public void summary(int x , int y){
this.x = x;
this.y = y;
a = x*y;
}
}
and in the Main class I wrote:
package com.company;
public class Main {
public static void main(String[] args) {
Second second = new Second();
second.summary(5, 7);
System.out.println(second.a);
}
}
and result is “0” every time. basically “null” but for integer.
In my logic what I’m doing is to call the “summary” method from the “Second” class and initializing “x” & “y”, and since I implemented an argument in said method which also initialize the “a” variable, I was expecting to see “35” as output, but needless to say that didn’t happen!
I really appreciate it if someone could help me understand what’s going on here and why is this happening. thanks!