diff --git a/Capture 6.png b/Capture 6.png new file mode 100644 index 0000000..a4ae8df Binary files /dev/null and b/Capture 6.png differ diff --git a/Capture 7.png b/Capture 7.png new file mode 100644 index 0000000..8b76bd4 Binary files /dev/null and b/Capture 7.png differ diff --git a/Capture 8.png b/Capture 8.png new file mode 100644 index 0000000..fafa6ea Binary files /dev/null and b/Capture 8.png differ diff --git a/Questions.txt b/Questions.txt index e84d3a1..b90a0ae 100644 --- a/Questions.txt +++ b/Questions.txt @@ -391,3 +391,33 @@ B) A FileNotFoundException is thrown to the caller C) An SQLException is thrown to the caller D) close methods of resources "one" and "two" are called E) close methods of resources "one" and "two" are not both called + +Q) Given +public int getValue() {return 1;} +public CharSequence getText() {return null;} + +which of these methods may individually be added to a subclass of this class? + +A) public int getValue(int x) {return 1;} +B) public String getValue() {return "Hello";} +C) public String getValue(int x) {return "Hello";} +D) public StringBuilder getText() { return null; } +E) public Object getText() { return ""; } + +Q) Given: + void doStuff(int x, long y) {} // Method B + void doStuff(long x, int y) {} // Method C + void doStuff(int ... x) {} // Method D + void doStuff(Integer x, Integer y) {} // Method E + +and: + doStuff(1, 2); + +What happens: +A) compilation fails +B) method B is called +C) method C is called +D) method D is called +E) method E is called + +Q) \ No newline at end of file diff --git a/src/main/java/overloadresolution/Example.java b/src/main/java/overloadresolution/Example.java new file mode 100644 index 0000000..268e724 --- /dev/null +++ b/src/main/java/overloadresolution/Example.java @@ -0,0 +1,16 @@ +package overloadresolution; + +public class Example { +// void doStuff(int x, int y) {} // Method B +// void doStuff(int x, long y) {} // Method B +// void doStuff(int x, double y) {} // Method B +// void doStuff(long x, int y) {} // Method C + void doStuff(int ... x) {} // Method D + void doStuff(Integer x, Integer y) {} // Method E + void doStuff(Integer x, Number y) {} // Method E + void doStuff(Number x, Integer y) {} // Method E + + public void useIt() { + doStuff(1, 2); + } +}