Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quiz & Code Challenges #8

Open
wants to merge 178 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
bac5daf
update
amideb Mar 21, 2023
4638517
update
amideb Mar 21, 2023
9648ec1
update
amideb Mar 21, 2023
6f26323
update
amideb Mar 21, 2023
26f7ea2
update
amideb Mar 21, 2023
62de71f
update
amideb Mar 21, 2023
2516d30
update
amideb Mar 21, 2023
1dda794
update
amideb Mar 21, 2023
a1593b9
update
amideb Mar 21, 2023
151c0e0
update
amideb Mar 21, 2023
61b6aae
update
amideb Mar 21, 2023
97bc05c
update
amideb Mar 21, 2023
04e0d05
update
amideb Mar 21, 2023
1f48644
update
amideb Mar 21, 2023
f8193a7
update
amideb Mar 21, 2023
fee7d79
Thank You
amideb Mar 23, 2023
1020d09
Thank You
amideb Mar 23, 2023
e542acc
Thank You
amideb Mar 23, 2023
19dc1f5
.
amideb Mar 23, 2023
341886f
.
amideb Mar 23, 2023
d15b969
.
amideb Mar 23, 2023
40e9640
.
amideb Mar 23, 2023
a8e86d7
.
amideb Mar 23, 2023
34cc46e
.
amideb Mar 23, 2023
1c73b37
.
amideb Mar 23, 2023
83217ba
.
amideb Mar 23, 2023
d195173
.
amideb Mar 23, 2023
d6e97bc
.
amideb Mar 23, 2023
ff1eb88
.
amideb Mar 23, 2023
cc408a3
.
amideb Mar 23, 2023
31436f5
.
amideb Mar 23, 2023
006d202
.
amideb Mar 23, 2023
cfb97dc
Update CODECHALLENGE.md
amideb Mar 24, 2023
649d7ca
Update QUIZ.md
amideb Mar 24, 2023
ad9fee4
.
amideb Mar 24, 2023
e98c08e
.
amideb Mar 24, 2023
08f0de9
.
amideb Mar 24, 2023
cb06073
.
amideb Mar 24, 2023
ff5d09e
.
amideb Mar 24, 2023
665b4c4
.
amideb Mar 25, 2023
3ee9713
.
amideb Mar 25, 2023
984221b
.
amideb Mar 25, 2023
de4716c
.
amideb Mar 25, 2023
f22d03a
.
amideb Mar 25, 2023
44d9a6a
.
amideb Mar 25, 2023
da24e64
.
amideb Mar 25, 2023
3d94e7f
.
amideb Mar 25, 2023
d4c096f
.
amideb Mar 25, 2023
06cfcd7
.
amideb Mar 25, 2023
c3e87eb
.
amideb Mar 25, 2023
d388148
.
amideb Mar 25, 2023
d16dc28
.
amideb Mar 25, 2023
8c8553a
.
amideb Mar 25, 2023
720ec45
.
amideb Mar 25, 2023
5374506
.
amideb Mar 25, 2023
60ccc32
.
amideb Mar 25, 2023
9c96c61
.
amideb Mar 25, 2023
851991c
.
amideb Mar 25, 2023
92ad6d4
.
amideb Mar 25, 2023
9c24144
.
amideb Mar 25, 2023
cae00fa
.
amideb Mar 25, 2023
a84c144
.
amideb Mar 25, 2023
05862d7
.
amideb Mar 26, 2023
dcca7ee
.
amideb Mar 26, 2023
c9b8fa3
.
amideb Mar 26, 2023
3cf98f3
.
amideb Mar 26, 2023
59e35d8
.
amideb Mar 26, 2023
0932244
.
amideb Mar 26, 2023
828f6b6
.
amideb Mar 26, 2023
8ff106b
.
amideb Mar 26, 2023
3d2464f
.
amideb Mar 26, 2023
6ac4fc8
.
amideb Mar 26, 2023
faaf7a5
.
amideb Mar 26, 2023
8fa517d
.
amideb Mar 26, 2023
27f81fb
.
amideb Mar 26, 2023
586f618
.
amideb Mar 26, 2023
35035be
.
amideb Mar 26, 2023
942c26d
.
amideb Mar 26, 2023
7f188b8
.
amideb Mar 28, 2023
58cbb7f
.
amideb Mar 28, 2023
8d1d399
.
amideb Mar 28, 2023
7aa5189
.
amideb Mar 28, 2023
4b62fb6
.
amideb Mar 28, 2023
d149c3a
.
amideb Mar 28, 2023
b4cd7cd
.
amideb Mar 28, 2023
fe2723b
.
amideb Mar 28, 2023
81df5f5
.
amideb Mar 28, 2023
ba759da
.
amideb Mar 29, 2023
82440b0
.
amideb Mar 29, 2023
780e781
Create 03-IntroductionToJavaPlatform.md
amideb Mar 31, 2023
2a1b5be
.
amideb Mar 31, 2023
ef0533f
.
amideb Mar 31, 2023
28854b3
.
amideb Apr 1, 2023
f7c1d9e
.
amideb Apr 1, 2023
944c1fc
.
amideb Apr 1, 2023
f4da97f
.
amideb Apr 2, 2023
d221fc4
Update 05-IntroductionToObjectOrientedProgrammin.md
amideb Apr 2, 2023
050714b
.
amideb Apr 2, 2023
f6b8f3f
.
amideb Apr 2, 2023
9e99b5b
.
amideb Apr 4, 2023
655ede0
.
amideb Apr 4, 2023
f2b9c19
.
amideb Apr 4, 2023
a61fefb
Update Q05-IntroductionToObjectOrientedProgrammin.md
amideb Apr 4, 2023
2a7cc0b
Update Q05-IntroductionToObjectOrientedProgrammin.md
amideb Apr 4, 2023
aaef942
.
amideb Apr 5, 2023
cacd7ce
.
amideb Apr 5, 2023
1bfa155
Update 03-IntroductionToJavaPlatform.md
amideb Apr 8, 2023
5288e77
.
amideb Apr 10, 2023
d3ab262
.
amideb Apr 10, 2023
a781dc0
.
amideb Apr 10, 2023
dca7682
.
amideb Apr 10, 2023
e0f6f38
.
amideb Apr 10, 2023
dc9998e
.
amideb Apr 10, 2023
2441d3a
Update 05-RENEW.md
amideb Apr 10, 2023
0028f48
...
amideb Apr 10, 2023
825d9e4
.
amideb Apr 10, 2023
bc5fb0d
.
amideb Apr 10, 2023
b6f2245
.
amideb Apr 15, 2023
141a254
.
amideb Apr 15, 2023
54920d0
.
amideb Apr 15, 2023
374b3b3
.
amideb Apr 15, 2023
ac414cb
.
amideb Apr 15, 2023
f638928
.
amideb Apr 24, 2023
407ade5
Update 06-PrimitiveDataTypesAndAlternatives.md
amideb Apr 24, 2023
31ccc91
.
amideb Apr 25, 2023
e6a3851
.
amideb Apr 25, 2023
4815fb1
Update 07-Conditionals.md
amideb Apr 25, 2023
45ce4be
h
amideb Apr 25, 2023
636eaca
.
amideb Apr 25, 2023
4f1b5a6
.
amideb May 3, 2023
7f41611
.
amideb May 3, 2023
913d49a
.
amideb May 3, 2023
11adc12
Update 08-Loops.md
amideb May 3, 2023
ed45d45
.
amideb May 3, 2023
aed13df
.
amideb May 4, 2023
092427b
.
amideb May 4, 2023
5efc571
.
amideb May 4, 2023
2544a1a
.
amideb May 4, 2023
91d03e9
.
amideb May 4, 2023
ab0ff2b
.
amideb May 4, 2023
f93f296
.
amideb May 5, 2023
48c340b
.
amideb May 6, 2023
6c8e3db
.
amideb May 6, 2023
117eb74
.
amideb May 6, 2023
f728364
.
amideb May 6, 2023
5034a90
.
amideb May 7, 2023
8ffaebc
.
amideb May 7, 2023
bd17633
.
amideb May 7, 2023
8805d42
.
amideb May 7, 2023
bce3b6f
.
amideb May 7, 2023
1da13d3
.
amideb May 7, 2023
981c59e
Update Q11-ObjectOrientedProgrammingAgain.md
amideb May 7, 2023
9e5c910
.
amideb May 7, 2023
987017f
.
amideb May 11, 2023
8b90951
.
amideb May 13, 2023
cec806b
.
amideb May 21, 2023
93abae0
.
amideb May 21, 2023
6624f60
.
amideb May 21, 2023
a65c107
.
amideb May 21, 2023
a42530a
Update Q02-IntroductionToMethods-MultiplicationTable.md
amideb May 21, 2023
f5556db
.
amideb May 21, 2023
51ff016
.
amideb May 21, 2023
cac877b
.
amideb May 21, 2023
3d3dbbe
Create 1.md
amideb May 22, 2023
c2b3a7c
Rename 1.md to Q01-IntroductionToJavaProgrammingWithJShell-Multiplica…
amideb May 22, 2023
598db48
Create Q13-Generics.md
amideb May 25, 2023
4daf212
Create Q13-Generics.md
amideb May 25, 2023
620ffe9
Create Q14-FunctionalProgramming.md
amideb May 25, 2023
45d32eb
Create Q15-ThreadsAndConcurrency.md
amideb May 25, 2023
5abd8a3
Create Q16-ExceptionHandling.md
amideb May 25, 2023
0dbc4da
Create Q17-Files.md
amideb May 25, 2023
1390869
Create Q17-Files.md
amideb May 25, 2023
4529da9
Create Q16-ExceptionHandling.md
amideb May 25, 2023
80e60f6
Create Q15-ThreadsAndConcurrency.md
amideb May 25, 2023
908ad54
Update Q15-ThreadsAndConcurrency.md
amideb May 25, 2023
4644ee2
Create Q14-FunctionalProgramming.md
amideb May 25, 2023
85b2180
Update Q14-FunctionalProgramming.md
amideb May 25, 2023
a32cc91
.
amideb May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

251 changes: 251 additions & 0 deletions 00-Quiz-Explanation/Q02-IntroductionToMethods-MultiplicationTable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
### Question 1



What does the `void` keyword indicate in a method definition?



* A) The method returns an integer value. `Incorrect: void` means no return type, not integer.

* B) The method does not return any value. `Correct: void` means the method does not return any value.

* C) The method returns a boolean value. `Incorrect: void` means no return type, not boolean【5†source】.



### Question 2



What is the correct way to call a method named `sayHelloWorldTwice`?



* A) sayHelloWorldTwice. `Incorrect: Method calls in Java require parentheses, even if no arguments are being passed`.

* B) sayHelloWorldTwice(). `Correct: This is the correct syntax to call a method in Java`.

* C) sayHelloWorldTwice(); `Incorrect: While this is valid in a statement context, it's not the correct way to just refer to a method call`【6†source】.



### Question 3



Which of the following statements is true about method definitions and method calls?



* A) Defining a method automatically executes its statement body. `Incorrect: Defining a method does not execute its body`.

* B) Defining a method and invoking it are the same thing. `Incorrect: Defining a method is different from invoking it`.

* C) Defining and invoking methods are two different steps. `Correct: In Java, a method must first be defined and then invoked for the code in the method to execute`【7†source】.



### Question 4



What is the correct syntax for defining a method that prints "Hello World"?



* A) void printHelloWorld() { System.out.println("Hello World"); }. `Correct: This is the correct syntax for defining a method in Java`.

* B) printHelloWorld() { System.out.println("Hello World"); }. `Incorrect: Java methods require a return type, in this case, 'void' is missing`.

* C) void printHelloWorld { System.out.println("Hello World"); }. `Incorrect: Parentheses are required after the method name to indicate it's a method`【8†source】.



### Question 5



Which of these method names follows the same naming rules as variable names?



* A) 1stMethod. `Incorrect: Variable names cannot start with a number`.

* B) method_one. `Correct: This follows the Java naming rules, can contain alphanumeric characters and underscores, and cannot start with a number`.

* C) first-Method. `Incorrect: Hyphens are not allowed in Java method names`【9†source】.



### Question 6



Which command lists the methods defined in the current JShell session?



* A) /methods. `Correct: This command lists the methods defined in the current JShell session`.

* B) /list. `Incorrect: This command lists the statements entered during the current JShell session`.

* C) /edit. `Incorrect: This command opens a method definition in a separate editor window`【10†source】.



### Question 7



What does the /edit command do in JShell?



* A) Lists the code of the specified method. `Incorrect: This is not the function of the /edit command`.

* B) Allows you to modify the method definition in a separate editor window. `Correct: The /edit command opens the definition of a method in a separate editor window for modification`.

* C) Saves the session method definitions to a file. ``Incorrect: This is the functionality of the /save command, not /edit`【11†source】.



### Question 8



What is the correct syntax for defining a method with an argument?



* A) void methodName(ArgType argName) { method-body }. `Correct: This is the correct syntax to define a method with arguments in Java`.

* B) methodName(ArgType argName) { method-body }. `Incorrect: Java methods require a return type`.

* C) methodName(ArgType argName) { method-body; }. `Incorrect: The semicolon at the end is not necessary and the return type is missing`【12†source】.



### Question 9



Which method definition correctly prints all integers from 1 to n (inclusive), where n is an argument?



* A)



void printNumbers(int n) {

for (int i = 1; i <= n; i++) {

System.out.println(i);

}

}

`Correct: This method correctly prints all integers from 1 to n`【13†source】.



### Question 10



What would happen if you try to call the method `sayHelloWorld` with a string argument, when the method is defined to accept an integer argument?



* A) The program will compile and run without any errors. `Incorrect: The method call will fail to compile due to incompatible types`.

* B) The program will throw a runtime error. `Incorrect: The error will occur at compile time, not runtime`.

* C) The program will fail to compile due to incompatible types. `Correct: Java is statically-typed, meaning the type of each variable and expression is checked at compile time`【14†source】.




### Question 11

What is method overloading in Java?

* A) The ability to have multiple methods with the same name in a class, but with different types of arguments. `Correct: Method overloading allows multiple methods with the same name but different parameter lists in a class`.
* B) The ability to have multiple methods with the same name and the same types of arguments in a class. `Incorrect: Methods with the same name and argument types are considered duplicates and will result in a compilation error`.
* C) The ability to have a single method with an arbitrary number of arguments. `Incorrect: This describes varargs, not method overloading`【16†source】.

### Question 12

Consider the following two method definitions:

```java
void printName(String firstName, String lastName) {
System.out.println(firstName + " " + lastName);
}

void printName(String firstName, String middleName, String lastName) {
System.out.println(firstName + " " + middleName + " " + lastName);
}
```

Which of the following statements are true?

- A) The two methods are overloaded methods. `Correct: These methods have the same name but different parameters, which is a feature of method overloading`.
- B) The two methods have the same name and different number of arguments. `Correct: These methods indeed have the same name but different number of arguments`.
- C) The two methods have the same name and the same types of arguments. `Incorrect: While they have the same types of arguments, the number of arguments is different, so this statement is false`【17†source】.

### Question 13

What will the following code snippet output?

```
void sum(int a, int b) {
System.out.println(a + b);
}

void sum(int a, int b, int c) {
System.out.println(a + b + c);
}

sum(1, 2);
sum(1, 2, 3);
```

- A) The output will be 3 6. `Correct: The first call to sum uses the two-parameter version, while the second call uses the three-parameter version`.
- B) The output will be 3 5. `Incorrect: The second call to sum(1,2,3) would yield 6, not 5`.
- C) The code will not compile due to method overloading. `Incorrect: Method overloading is a valid concept in Java, and this code would compile and run correctly`【18†source】.

### Question 14

Which of the following statements is true about methods with multiple arguments in Java?

- A) A method can only accept up to 2 arguments. `Incorrect: A method in Java can accept any number of arguments`.
- B) A method can accept any number of arguments, but they must be of the same type. `Incorrect: A method can accept arguments of different types`.
- C) A method can accept any number of arguments, and they can be of different types. `Correct: In Java, a method can accept any number of arguments, and these arguments can be of different types`【19†source】.

### Question 15

What is the main purpose of method overloading in Java?

- A) To reduce code duplication by allowing methods with the same name but different arguments. `Correct: One of the benefits of method overloading is that it allows the same method name to be used with different parameters`.
- B) To allow a method to return different types of values based on the input arguments. `Incorrect: Method overloading does not affect the return type of a method`.
- C) To create multiple methods with the same name and the same number of arguments, but with different implementation. `Incorrect: The methods would need to have different parameter lists to be considered overloaded`【20†source】.

### Question 16

What is the purpose of a return statement in a method?

- A) To end the execution of the method. `Incorrect: While a return statement does end the execution of a method, its main purpose is to return the result of a computation to the calling code`.
- B) To return the result of a computation to the calling code. `Correct: The primary purpose of the return statement in a method is to return the result of a computation to the calling code`.
- C) To print the output of the method. `Incorrect: Printing the output is the job of the System.out.println() method, not the return statement`【21†source】.

### Question 17

What is the benefit of using a return mechanism in a method?

- A) It allows the method to print the result of the computation. `Incorrect: Printing is not the job of the return statement, rather it returns the result to the calling code`.
- B) It enables sharing computed results with other code and methods, and improves breaking down a problem into sub-problems. `Correct: The return mechanism enables the reuse of computed results in other parts of the code`.
- C) It simplifies the syntax of the method. `Incorrect: While the use of return can make a method more readable, it does not necessarily simplify the syntax`【22†source】.
Loading