Question: Quick question about java. So if I have two objects from the main class and I'm trying to add them together. how can I create
Quick question about java.
So if I have two objects from the main class and I'm trying to add them together. how can I create a method to add whatever those two objects?
I tried to do it here but I could not finish it.
package Bright;
public class partic { public int conNumber; public partic(int number) { conNumber = number; } public partic add(partic sum) {
return null; } }
--------------------------------
package Bright;
public class particDemo { public static void main (String[] args) { partic val1 = new partic(23); System.out.println("val one is " + val1.conNumber); partic val2 = new partic(54); System.out.println("val one is " + val2.conNumber); partic sum; sum = val1.add(val2); System.out.println("The sum: " + sum); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
