Advertisement
plamen27

Compile Test OOP quest

Jun 7th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. What is the result of compiling and running the following class:
  2.  
  3. class Test
  4. {
  5. public void methodA(int i)
  6. {
  7. System.out.println(i);
  8.  
  9. }
  10. public int methodA(int i)
  11. {
  12. System.out.println(i+1);
  13. return i+1;
  14. }
  15. public static void main(String args[])
  16. {
  17. Test X = new Test();
  18. X.methodA(5);
  19. }
  20. }
  21.  
  22. (A) The program compiles and runs printing 5.
  23. (B) The program compiles and runs printing 6.
  24. (C) The program gives runtime exception because it does not find the method Test.methodA(int)
  25. (D) The program give compilation error because methodA is defined twice in class Test.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement