Skip to content

Commit

Permalink
Update java-quiz.md (#7)
Browse files Browse the repository at this point in the history
I passed it this morning, so I updated the ones I remembered. I tested most of the code snippet ones just to double check.
  • Loading branch information
ajmeese7 authored May 19, 2020
1 parent 559da50 commit fda523a
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions java/java-quiz.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Java Assessment

#### Q1. Given the string "strawberries" saved in a variable called fruit, what would "fruit.substring(2, 5)" return?
- rawb
- raw
- raw <<<<---Correct
- awb
- traw

#### Q2. How can you achieve runtime polymorphism in Java?
- method overloading
- method overloading <<<<---Correct
- method overrunning
- method overriding
- method calling
Expand All @@ -18,28 +18,28 @@ Java Assessment
int i1 = 1, i2 = 2;`

- (i1 | i2) == 3
- i2 & b1
- b1 | !b2
- i2 && b1 <<<<---Correct
- b1 || !b2
- (i1 ^ i2) < 4

#### Q4. What can you use to create new instances in Java?
- constructor
- constructor <<<<---Correct
- another instance
- field
- private method

#### Q5. What is the output of this code?
```shell script
1: class Main {
2: public static void main (String[] args)
2: public static void main (String[] args) {
3: int array[] = {1, 2, 3, 4};
4: for (int i=0; i<array.size(); i++){
5: System.out.print(array[i]);
}
}
}
4: for (int i = 0; i < array.size(); i++) {
5: System.out.print(array[i]);
}
}
}
```
- It will not compile because of line 4.
- It will not compile because of line 4. <<<<---Correct
- It will not compile because of line 3.
- 123
- 1234
Expand Down Expand Up @@ -69,25 +69,25 @@ System.out.println(str);
- CD
- CDE
- D
- "abcde"
- "abcde" <<<<---Correct

#### Q8. What is the result of this code?
```
1: class Main {
2: public static void main (String[] args){
3: System.out.printlin(print(1));
3: System.out.println(print(1));
4: }
5: static Exception print(int i){
6: if (i>0) {
7: return new Excepton();
7: return new Exception();
8: } else {
9: throw new RuntimeException();
10: }
11: }
12: }
```
- It will show a stack trace with a runtime exception.
- "java.lang.Exception"
- "java.lang.Exception" <<<<---Correct
- It will run and throw an exception.
- It will not compile.

Expand Down Expand Up @@ -143,7 +143,7 @@ class Three implements One, Two {
```
- The code does not compile.
- truefalse
- truetrue
- truetrue <<<<---Correct
- falsetrue

#### Q11. Given the following two classes, what will be the output of the Main class?
Expand Down Expand Up @@ -220,7 +220,7 @@ class Main {
}
```
- "123451234512345"
- Nothing - this will not compile.
- Nothing - this will not compile. <<<<---Correct
- a negative integer value
- "12345100000"

Expand All @@ -236,7 +236,7 @@ class Main {
}
```
- The code does not compile.
- A runtime exception is thrown
- A runtime exception is thrown <<<<---Correct
- "world!!world"
- "world!world!"

Expand All @@ -246,9 +246,8 @@ String n = m.substring(6,12) + m.substring(12,6);
System.out.println(n);
```

#### Q17. What is the output of this code?
- How do you write a foreeach loop that will iterate over
```ArrayList<Pencil>pencilCase?
#### Q17. How do you write a foreach loop that will iterate over ArrayList\<Pencil\>pencilCase?
```
for(Pencil pencil = pencilCase){}
Iterator iterator = pencilCase.iterator();
Expand Down

0 comments on commit fda523a

Please sign in to comment.