Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Problem with the code

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Problem with the code

    Untitled.jpg

    could anyone help me? thanks

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with the code

    Please copy and paste here as text what you want us to see. The image is hard to read and no text can be copied from an image to include in a response.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    AleksandraVulisic (August 26th, 2017)

  4. #3
    Junior Member
    Join Date
    Aug 2017
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Problem with the code

    When i want to make a public class,there is an error in the program that said "The public type NameOfClass must be defined in its own file", and i don't know how to do that. Can you please tell me?

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with the code

    in its own file
    The name of the java source file must match the name of the public class it contains.
    public class XYZ
    must be in the file XYZ.java
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    AleksandraVulisic (August 26th, 2017)

  7. #5
    Junior Member
    Join Date
    Aug 2017
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Problem with the code

    But what happens when i have to extends some class? I had try it and it's a mistake.
    for example:
    public class ABX{
    //some txt
    }
    public class Letters extends ABX{
    //some txt
    }
    it said that Letters must be defined in its own file

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with the code

    There can only be ONE public class in a source file. Only the class whose name matches the source file name can be public.
    Remove the public attribute for the other classes.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    AleksandraVulisic (August 26th, 2017)

Similar Threads

  1. I am in problem with my code
    By mohakal06r in forum Member Introductions
    Replies: 2
    Last Post: February 26th, 2012, 01:03 AM
  2. PROBLEM WITH MY CODE!!!!
    By vaughn00AoG in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 26th, 2012, 10:28 AM
  3. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  4. Problem with code
    By lichad3 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 22nd, 2011, 06:40 PM
  5. problem in my code
    By wannabe in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 24th, 2010, 07:53 AM