Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public class Methods
  2. {
  3. private int x;
  4. public static void hello()
  5. {
  6. System.out.println("Hello, world!");
  7. }
  8. public void print()
  9. {
  10. System.out.println("x is: "+x);
  11. }
  12. public void setX(int x)
  13. {
  14. this.x=x;
  15. }
  16. public Methods(int x)
  17. {
  18. setX(x);
  19. }
  20. public int getX()
  21. {
  22. return this.x;
  23. }
  24. static void print(Methods m)
  25. {
  26. m.print();
  27. }
  28. public static void main(String[] args)
  29.  
  30. Methods m = new Methods(42);
  31. hello();
  32. m.print();
  33. m.setX(34);
  34. System.out.println("m.getX: " + m.getX());
  35. print(m);
  36. }
  37.  
  38.  
  39. Methods.java:28: error: ';' expected
  40. public static void main(String[] args)
  41. ^
  42. Methods.java:31: error: invalid method declaration; return type required
  43. hello();
  44. ^
  45. Methods.java:32: error: <identifier> expected
  46. m.print();
  47. ^
  48. Methods.java:33: error: <identifier> expected
  49. m.setX(34);
  50. ^
  51. Methods.java:33: error: illegal start of type
  52. m.setX(34);
  53. ^
  54. Methods.java:34: error: <identifier> expected
  55. System.out.println("m.getX: " + m.getX());
  56. ^
  57. Methods.java:34: error: illegal start of type
  58. System.out.println("m.getX: " + m.getX());
  59. ^
  60. Methods.java:35: error: invalid method declaration; return type required
  61. print(m);
  62. ^
  63. Methods.java:35: error: <identifier> expected
  64. print(m);
  65. ^
  66. 9 errors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement