Alexandru Puiu

Greenhorn
+ Follow
since Feb 22, 2017
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Alexandru Puiu

Already found the answer! Thank's in advance!
5 months ago
Hi guys,

Can someone please help me understand why do I get an exception here:



My compiler doesn't find anything wrong, but I get the following exception:

5 months ago
So if the exceptions are unchecked it compiles, but if not it does not? 
Ok, now I'm a little confuse as to why is Exception legal. I mean there is no checked exception that the code can throw that is not already a HurtException, right?

I always though that as long as the exceptions declared in the catch blocks argument are in order from the most specific to the most broad, everything is ok.  Like in the example below:


Further more in the book at page 310, there is actually an example about something similar, but the exceptions there are unchecked exceptions. As a general rule: if the exceptions are unchecked it compiles, but if not it does not? 
 
I'm using Intellij IDEA 2016.2.1 and code with Limp Exception compiles fine... I'm using java 8 that's 100%. 

I've tried to code in a notepad and it doesn't compile... What should I make of this? Is the notepad the office version? And why? Doesn't both use the same JMV?
Hi there!

First of all, the book and it's content have been very helpful, but i don't know about the online tests. This is the last mistake I've encounter (as in not the only one). I hope I'm mistaking, but I don't think so:

The question is:
Which of the following can fill in the blank to make the code compile? (Choose all that apply)


Answers: Exception, HurtException, IOException, LimpException, RuntimeException

Correct answers according to the test are only Exception and RuntimeException, when in it is clearly (according to my IDE) that with also LimpException, the cod compiles. Am I missing something here? I mean I get a warning from the IDE, but it compiles.

. Maybe you redefine super1 later to really be a Super. So the compiler is protecting you.

"   -- now I get the logic behind it. Thank you!
8 months ago
Yeah, but the method "method()" is overridden at line 25 in Sub. So it is not Super's method anymore. It should be Sub's method.  If you look at line 14, "anotherMethod()" is also overridden and the output is  "In sub". Like it should be. I'm sure that if I write throws Exception is the main method declaration, and put "System.out.println("In sub");" also in the "method()" at line 25, the code will compile and the output will be "In sub".

I was wandering if you guys have an explanation on what is happening behind the curtains. Why doesn't the compiler accepts the call at line 16, considering that the method is overridden and is no longer the one from Super.
8 months ago
Hi there!

So I have the following code:



I don't get it. Why does "super1.method();" not compile? The method in the Sub is called and it doesn't declare any exceptions.

Are the exceptions thrown by the method in Super inherited by the method in Sub? And if so, why "sub.method();" compiles? Or is it more of a technicality? I though that after the method it's overridden, that method "belongs" to the object, not to the reference anymore. Polymorphism, right? I knew that Java still takes a look at the method in Super just to make sure I don't declare a broader exceptions, but I thought that was it.

Thanks in advance!
Alex
8 months ago
It helps me a lot! Thank you!
Hi there!

I've searched the internet and I couldn't find a real answer. I'm currently in Germany, and I want to take my exam here, but will I be able to choose English as the exam language? Or is the language country dependent? I mean, I'm just nervous that I will find myself in the exam room and obligated to take it in deutsch. My deutsch is Ok-ish, but I don't want to risk it...

Thanks in advance!
Alex

8 months ago
Hi there!

So I have the following code:


First of all I'm not sure if my question is actually about method overriding because I'm not sure what causes this. I understand why the result is(I mean how the overriding and hiding works) :

Beta 44
4 44
Beta 44
44 44

What I don't understand is why is not:
4 Beta 44
44
44 Beta 44
44

Operations in a System.out.println(), are done from left to right in this case, no? So "4" should have been first because it was hidden; then the method from Beta class comes next, because is was overridden: Beta 44; then the println from inside the method; and last the return from the method: 44, right? For the next System.out.println() is the same process only that h is 44....

Why is "System.out.println("Beta " + h)" from the b.getH() read first, then "b.h", then the return "44" from  b.getH() and last the println from the original System.out.println()?
8 months ago
Nice little test program! I've wouldn't have though at making one.

I've done the test in Java 8 and the output is the same:

m1 public abstract
m2 public abstract
m3 public abstract
m4 public abstract

Thank a lot for your answers guys! I know it is not necessarily something that you would hit yourself with in a real live working environment, but questions like this can be on the exam.
8 months ago
So, the answer is the book is incorrect. It this case I think if I will ever encounter this question in the exam, I will go with "the both are implicitly applied" answer.
8 months ago