1

Result:

public class cls1 
{
    short f1;

    short f2;

    byte f3;

  }

  public class cls2 
{
    short f4;

    short f5;

    byte f6;

  }

Result not like this :

public class cls1 
{
    short f1;

    short f2;

    byte f3;

  public class cls2 
{
    short f4;

    short f5;

    byte f6;

  }
}
Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
Priya K
  • 23
  • 3
  • remove public key word in your first appraoch and let me know. there cannot be 2 classes with public modifier if one class is public then file name should be class. If there is no public class then you can keep any of the class. Here I am not talking about nested class but 2 separate classes – Abdul Waheed Oct 31 '18 at 11:25
  • And read about java naming conventions. Class names should go UpperCase, always, even for examples. – GhostCat Oct 31 '18 at 13:35

2 Answers2

0

In Java you can have multiple top level classes in single .java file, but only one of them can be public.

FazoM
  • 4,385
  • 6
  • 41
  • 60
  • yes please. I added public by mistake, but i want to know if javapoet allows me to add two classes irrespective of access specifier to the same .java file. – Priya K Oct 31 '18 at 14:49
0

JavaPoet deliberately doesn’t support this. We recommend you use nesting or separate files instead.

Jesse Wilson
  • 36,548
  • 7
  • 116
  • 123