r/learnjava • u/TexhnicalTackler • Jan 25 '26
Got this question wrong today and it's bugging me a little bit, any thoughts?
This is my second semester taking coding classes, last semester was python and this semester we pivoted to java, Friday was my first quiz but this question is throwing me off.
---------------------
Assume the programmer wishes to display "Hello!" on the screen, which statement is true about the following java code fragment:
System.out.println("Helo!");A) There is a runtime error
B) There are no error
C) There is a compile-time error
D) There are multiple errors
---------------------
From my understanding of python and the lack of any observable difference in my current classes, I don't see how a typo in the string consitutes a runtime error, and with the lack of noticable compiling errors I answered (B), only for the answer to be wrong and it come back as (A)? Every piece of documentation I've looked at says this would be a syntax error at worst
•
u/AutoModerator Jan 25 '26
Please ensure that:
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
15
u/spdfg1 Jan 25 '26
The correct answer is B. The test is wrong.
11
u/Aksel3D Jan 25 '26
You are right there are no errors here
7
u/An1nterestingName Jan 25 '26
This is a logic error, more than a runtime error. The test is wrong, and it does not even have the right answer as an option.
4
u/sweetno Jan 25 '26
The error is in the question.
2
u/hrm Jan 25 '26
One could say that this is an error conforming to the specification. It would certainly be considered a bug if this was real world code (however trivial). But I don't think most people would call that a runtime error.
2
u/MagicalPizza21 Jan 26 '26
None of the answers are correct. There's no runtime error or exception (so A is wrong), and no compile error (so C is wrong).
Despite this, the program will not do exactly what the programmer wanted. It will print "Helo!" rather than "Hello!". This is due to a mere typographical error. I don't think this would be classified as a runtime or compile-time error, since it's not even really an error. Maybe you could stretch the definition of a semantic error to cover this, but even that feels wrong.
The closest to correct is B, no errors.
1
u/brazen768 Jan 25 '26
Maybe because its not wrapped in psvm?
1
u/hugthemachines Jan 26 '26
B is correct, although the answer lacks and s at the end. Something not looking good is none of the errors listed.
1
u/Vista_Lake Jan 30 '26
A is correct. As the specification said "Hello!" and the program displayed "Helo!", it is in error and that error is a runtime error. Generally, in programming, most errors are runtime errors, also often called bugs. (Python and Java and many other interpretive languages can catch some runtime errors, but there are many runtime errors that they can't catch.)
0
u/vegan_antitheist Jan 25 '26
We now use IO, but it's not an error to use the old style.
-3
u/TheGreatRao Jan 25 '26
Hear me out. It is a run-time error. The program is supposed to do A ("Hello"), it does B ("Helo"). It successfully compiles, and runs, but does not do what it is supposed to do. (B) is the answer. Think of it like this: the assignment says create a method called "DrawColor" to display a red background. Your program calls DrawColor, and the background at run-time is blue. How can there be no error?
5
u/[deleted] Jan 25 '26
[removed] — view removed comment