Menu

Quick Question Java Two Objects Main Class M Trying Add Together Create Method Add Whateve Q43778241

Quick question about java.

So if I have two objects from the main class and I’m trying toadd them together. how can I create a method to add whatever thosetwo 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);
}
}

Expert Answer


Answer to 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 c…

OR