Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By JosAH

Thread: Class is public, should be declared in a file

  1. #1
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default Class is public, should be declared in a file

    Line 265: public class Inventory



    { // begin class Inventory



    CDInventoryProgram.java:265: class Inventory is public, should be declared in a
    file named Inventory.java
    public class Inventory
    ^


    Help Please anyone

  2. #2
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    This happens when you write two public classes inside the same file.
    In this case you need to have a file called Inventory.java and include the class in it.

  3. #3
    vanms1989 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    can you give some example here . thanks :D

  4. #4
    demonick is offline Member
    Join Date
    Dec 2010
    Posts
    27
    Rep Power
    0

    Default

    A .java file can have only 1 public class and more non-public classes(with no modifiers), which must have the same name as the .java file.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,996
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by vanms1989 View Post
    can you give some example here . thanks :D
    You replied to a three year old thread; it is stone dead, it doesn't even smell funny anymore. Please start your own thread if you have problems with your Java program.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    vanms1989 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    OK. thanks for help !

  7. #7
    Join Date
    May 2012
    Posts
    1
    Rep Power
    0

    Default Re: Class is public, should be declared in a file

    Quote Originally Posted by goldhouse View Post
    Line 265: public class Inventory



    { // begin class Inventory



    CDInventoryProgram.java:265: class Inventory is public, should be declared in a
    file named Inventory.java
    public class Inventory
    ^

    Help Please anyone

    hey friend just change our file name of java file into the class file name .............

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,996
    Blog Entries
    7
    Rep Power
    19

    Default Re: Class is public, should be declared in a file

    Oh please; this thread has gone to meet its maker; it is an ex-thread; it is pushing up the daisies; it joined the choir invisible; I'm closing it now; let it rest.

    kind regards,

    Jos
    DarrylBurke likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. public declaration ('undeclaring')
    By Jadellll in forum New To Java
    Replies: 2
    Last Post: 03-17-2008, 08:50 PM
  2. Public Holidays (Australia)
    By oranjeBoven in forum Advanced Java
    Replies: 0
    Last Post: 02-13-2008, 08:14 AM
  3. Public class variable
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 09:58 AM
  4. public method
    By dirtycash in forum New To Java
    Replies: 4
    Last Post: 11-21-2007, 07:29 PM
  5. Convert my class file into a exe file
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 08:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •