Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39457
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Martin Gregorie <martin@mydomain.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Surprise! |
| Date | Sun, 26 Apr 2020 13:00:20 -0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 63 |
| Message-ID | <r840l4$ius$1@dont-email.me> (permalink) |
| References | <Main.java-20190919202538@ram.dialup.fu-berlin.de> <r83j0k$f1$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Sun, 26 Apr 2020 13:00:20 -0000 (UTC) |
| Injection-Info | reader02.eternal-september.org; posting-host="115ad4a771d1cede00d26b1d1dc3c922"; logging-data="19420"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+QqlAZZvwAqmlQMbhkj6Dslv62etVVbs=" |
| User-Agent | Pan/0.146 (Hic habitat felicitas; 8107378 git@gitlab.gnome.org:GNOME/pan.git) |
| Cancel-Lock | sha1:0lVtv9igFPxB68ibuvfuuQMlN/s= |
| Xref | csiph.com comp.lang.java.programmer:39457 |
Show key headers only | View raw
On Sun, 26 Apr 2020 05:06:48 -0400, Jeff Higgins wrote:
> On 9/19/19 3:28 PM, Stefan Ram wrote:
>> Write this:
>>
>> public final class A { public static void main( final
>> java.lang.String[] args )
>> { B.hello(); }}
>>
>> public final class B { public static void hello()
>> { java.lang.System.out.println( "Hello!" ); }}
>>
>> and save it as "Main.java". Then call:
>>
>> java Main.java
>>
>> with a recent JDK. What you have there is a file named "Main.java"
>> that does /not/ contain a class "Main", and it has /two/ public
>> classes. Yet, the above command will happily print,
>>
Not here. I rearranged your source because I prefer opening and closing
brackets to align. Here's the result:
$ cat Main.java
public final class A
{
public static void main( final java.lang.String[] args )
{
B.hello();
}
}
public final class B
{
public static void hello()
{
java.lang.System.out.println( "Hello!" );
}
}
$ javac -version
javac 1.8.0_242
$ javac Main.java
Main.java:1: error: class A is public, should be declared in a file named
A.java
public final class A
^
Main.java:9: error: class B is public, should be declared in a file named
B.java
public final class B
^
2 errors
This is using Open Java 1.8 installed from the RedHat Fedora 31 package
repository and is exactly what I'd expect to see, since the name of a non-
nested class declaration should match the sourcefile name.
--
Martin | martin at
Gregorie | gregorie dot org
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Surprise! Jeff Higgins <invalid@invalid.org> - 2020-04-26 05:06 -0400
Re: Surprise! Martin Gregorie <martin@mydomain.invalid> - 2020-04-26 13:00 +0000
Re: Surprise! Joerg Meier <joergmmeier@arcor.de> - 2020-04-27 09:13 +0200
Re: Surprise! Martin Gregorie <martin@mydomain.invalid> - 2020-04-27 12:12 +0000
Re: Surprise! Arne Vajhøj <arne@vajhoej.dk> - 2020-04-27 08:34 -0400
Re: Surprise! Martin Gregorie <martin@mydomain.invalid> - 2020-04-27 13:52 +0000
Re: Surprise! Arne Vajhøj <arne@vajhoej.dk> - 2020-04-27 10:04 -0400
Re: Surprise! Arne Vajhøj <arne@vajhoej.dk> - 2020-04-27 10:09 -0400
Re: Surprise! Eric Douglas <e.d.programmer@gmail.com> - 2020-04-27 06:36 -0700
Re: Surprise! Arne Vajhøj <arne@vajhoej.dk> - 2020-04-27 09:46 -0400
csiph-web