fork download
  1. import java.util.Scanner;
  2.  
  3. class A { // class is a keyword. All keywords are all lower-case
  4. int a1;
  5. public void VAS ()
  6. {
  7. Scanner src=new Scanner(System.in);
  8. // int a1; This variable is hiding the variable called a1 above
  9. System.out.println("Enter value a1"); // always prompt for input so that the user knows what to do
  10. a1=src.nextInt();
  11. }
  12. }
  13.  
  14.  
  15. class B { // class is a keyword. All keywords are all lower-case
  16. int b1;
  17. public void VBS ()
  18. {
  19. Scanner src=new Scanner(System.in);
  20. // int b1; This variable would hide the variable named b1 above
  21. System.out.println("Enter value b1"); // always prompt for input so that the user knows what to do
  22. b1=src.nextInt();
  23. }
  24. }
  25.  
  26. class C {
  27. public void VCS()
  28. {
  29. int c1;
  30.  
  31. // call the constructors of A and B to create objects
  32. A g = new A(); // A is a class name VAS is a method name
  33. B h = new B(); // B is a class name VBX is a method name
  34.  
  35. // call methods of A and B
  36. g.VAS();
  37. h.VBS();
  38.  
  39. c1=(g.a1 + h.b1);
  40. System.out.println(c1);
  41. }
  42. }
  43.  
  44. class D
  45. {
  46. public static void main (String args[]) { // needed opening brace here
  47. C c= new C();
  48. c.VCS();
  49. } // needed closing brace here
  50.  
  51. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty