Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39457

Re: Surprise!

From Martin Gregorie <martin@mydomain.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Surprise!
Date 2020-04-26 13:00 +0000
Organization A noiseless patient Spider
Message-ID <r840l4$ius$1@dont-email.me> (permalink)
References <Main.java-20190919202538@ram.dialup.fu-berlin.de> <r83j0k$f1$1@dont-email.me>

Show all headers | 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


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