Java Brain Teasers (@Java_Hokage) profile picture

Let’s change the world one build at a time. I post Java questions. #JavaHokageQuestions

National Capital Region
Joined October 2018
Photo by Java Brain Teasers (@Java_Hokage)Photo by Java Brain Teasers (@Java_Hokage)
14. Callable and Supplier are functional interfaces. Both are quite similar since they have an abstract, no-argument method that just supply a value. One of this throws an Exception. Which one is it? #Java #JavaHokageQuestions
64%Callable
36%Supplier
11 votes • Final results
5
Fields in an interface implicitly static and final since interface can't have behavior or state. Interfaces are intended to specify an interaction contract only and not implementation details. #Java #JavaHokageQuestions
2
13. Interface fields are implicitly ____? #Java #JavaHokageQuestions
29%static
21%final
50%both
24 votes • Final results
1
1
12. You can have a top-level static class. Example (inside StaticClass.java): public static StaticClass {} class NestedClass {} #Java #JavaHokageQuestions
17%true
83%false
0%It depends.
6 votes • Final results
1
Java however supports: 1: Multiple inheritance of implementation, ability to inherit method definitions from multiple classes 2: Multiple inheritance of type, ability of a class to implement more than one interface. docs.oracle.com/javase/tutor… #Java #JavaHokageQuestions
1
. . . What if methods or constructors from different superclasses instantiate the same field? Which method or constructor will take precedence? Because interfaces do not contain fields, you do not have to worry about problems that result from multiple inheritance of state.
1
1
For example, suppose that you are able to define a new class that extends multiple classes. When you create an object by instantiating that class, that object will inherit fields from all of the class's superclasses. . .
1
False. In object-oriented programming, multiple inheritance of state is the ability to inherit fields from multiple classes. Java doesn’t support this. #Java #JavaHokageQuestions
1
1
11. In Java, you can extend multiple classes since Java supports multiple inheritance of state. #Java #JavaHokageQuestions
23%true
54%false
23%It depends
13 votes • Final results
1
1
If you run this program, it will print “pass-by-value” proving Java is pass-by-value indeed. #Java #JavaHokageQuestions
1
1
Since Java is pass-by-value, it creates a copy of that reference, thus it will now operate on the new reference variable and not the original. Any assignment on the new reference variable will not affect the original. #Java #JavaHokageQuestions
1
1
When you run this program, it will print “pass-by-value” thus proving Java is pass-by-value indeed. #Java #JavaHokageQuestions
1
We can access objects by assigning it to a reference variable. When the reference variable is passed to a method, the code in the method operates on the original reference variable. This is called pass-by-reference.
1
1
Java is always pass-by-value. We can agree on this on native types. It gets confusing on objects.
1
1
This situation describes Deadlock.
10. Is Java pass-by-reference or pass-by-value? #Java #JavaHokageQuestions
47%pass-by-reference
45%pass-by-value
8%neither
38 votes • Final results
1
2
9
9. This describes a situation where two or more threads are blocked forever, waiting for each other. #Java #JavaHokageQuestions
91%Deadlock
0%Livelock
0%Race condition
9%Starvation
11 votes • Final results
1
3