This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!

Urs Waefler

Ranch Hand
+ Follow
since Mar 13, 2007
Cows and Likes
Cows
Total received
-7
In last 30 days
0
Total given
0
Likes
Total received
-9
Received in last 30 days
0
Total given
18
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Urs Waefler

If it is an instance field, then the reference determines which instance it is.

If it is an instance method, then the object determines which method it is.

Is this a correct understanding?
2 years ago
I think that the object determines which instance variable is used. Thus I do not fully understand this code yet.
2 years ago
This is the code: I do not understand why it prints 8. I would kindly ask for a clarification.
2 years ago
This is the code: It returns the higher value. To me it seems that there is an else missing. I do not understand why it does not always return y.
2 years ago
I think I understand. Let me try:

iArr is a reference variable that holds an array object. When you pass the variable to the method, a copy of the variable is passed. That means after there is the original reference variable and a copy of the original reference variable; both variables point to the same object. You can change the object's state either via the original reference variable or via the copy of the original reference variable.

Is this a correct undersanding?
2 years ago
I found these statements in a mock exam:

- Multiple inheritance of state includes ability to inherit instance methods from multiple classes.
- Multiple inheritance of state includes ability to inherit instance fields from multiple classes.
- Multiple inheritance of type includes ability to implement multiple interfaces and/or ability to extend from multiple clases.

They are true.

Explanation

Interfaces, classes, and enums are all "types". Java allows a class to implement multiple interfaces. In this way, Java supports multiple inheritance of types.
"State", on the other hand, is represented by instance fields and instance methods. Only a class can have instance fields/methods and therefore, only a class can have a state. (Fields defined in an interface are always implicitly static, even if you don't specify the keyword static explicitly. Therefore, an interface does not have any state.) Since a class is allowed to extend only from one class at the most, it can inherit only one state. Thus, Java does not support multiple inheritance of state.

I understand the explanation, but I do not understand why the first two statements are true.
it should be int n....
2 years ago
n is not incremented. Why? I do not understand the difference between ingt n and int[] n.
2 years ago
This is the code: It will compile but will throw AnotherException when run.

Explanation
m2() throws NewException, which is not caught anywhere. But before exiting out of the main method, finally must be executed. Since finally throw AnotherException (due to a call to m3() ), the NewException thrown in the try block ( due to call to m2() ) is ignored and AnotherException is thrown from the main method.

I thought the exception has to be caught; m2() throws NewException, which is not caught anywhere. I would kindly ask for a clarification.
2 years ago
The value 333 ist assigned to the variable value; the variable global has the value 111. Finally there is a statement return value, which returns 333. Thus we have 111 333 333.
2 years ago