Skip to content

Commit

Permalink
Day 2 Break 3
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHGR committed May 9, 2023
1 parent 544dcbf commit 40d6f14
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
Binary file added Capture 6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Capture 7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Capture 8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions Questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 16 additions & 0 deletions src/main/java/overloadresolution/Example.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 40d6f14

Please sign in to comment.