well detailed explanation...mam, how to receive value to 2 object from a user in oops class... public class Sample1 { public static void main(String a[]) { Sum obj1=new Sum(); Sum obj2=new Sum(); System.out.println("Enter 2 value for object1"); int num1=Sum(System.in); int num2=Sum(System.in); obj1.calculatesum(num1, num2); obj1.displaysum(); System.out.println("Enter 2 value for object2"); int num3=Sum(System.in); int num4=Sum(System.in); obj2.calculatesum(num3, num4); obj2.displaysum(); } } public class Sum { int c; void calculatesum(int x, int y) { c=x+y; } void displaysum() { System.out.println(c); }
Didn't understood clearly.....But hope this is what u want import java.util.Scanner; public class Sample1 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); Sum obj1=new Sum(); Sum obj2=new Sum(); System.out.println("Enter 2 values for object1 :"); int num1=sc.nextInt(); int num2=sc.nextInt(); obj1.calculatesum(num1, num2); obj1.displaysum(); System.out.println("Enter 2 values for object2 :"); int num3=sc.nextInt(); int num4=sc.nextInt(); obj2.calculatesum(num3, num4); obj2.displaysum(); } } class Sum { int c; void calculatesum(int x, int y) { c=x+y; } void displaysum() { System.out.println("Sum is: "+c); }}
@@codeeureka1501 thank u mam.. Oru karyam kudey chodichotte. Mam java theory part allethey programming padipikundoo youtubeil first time anu njan maminte channel kannuth then follow cheye cheyithu. Programming padipikundoo mam
@@athulya4322 no athulya... Currently i am finishing theory topics... I have uploaded some programming videos also.. But i will try to upload more programming videos soon