java build error ( javac )

Asked

Viewed 143 times

-1

I have a "poo1.java file":

package pootest;

public class init{
        public static void main(String[] args){
                Caneta bic1 = new Caneta();
                bic1.cor = "azul";
                bic1.tampada = true;
                bic1.ponta = 0.5f;
                bic1.carga = 45;
                bic1.modelo = "comun";
                bic1.rabiscar();
        }
}

and another file "pen.java":

package pootest;

class Caneta{
        String modelo;
        String cor;
        float ponta;
        int carga;
        boolean tampada = true;

        void tampar(boolean estado){
                tampada = estado;
        }

        void rabiscar(){
                if (tampada){
                        System.out.print("ta tampada seu jumnet$
                } else{
                        System.out.print("boiolage");
                }
        }
}

and when I compile poo1.java( javac poo1.java ) in the terminal this is the output:

poo1.java:3: error: class init is public, should be declared in a file named init.java public class init{ poo1.java:5: error: cannot find Symbol Pen bic1 = new Pen(); Symbol: class Pen Location: class init poo1.java:5: error: cannot find Symbol Bic1 pen = new Pen(); Symbol: class Pen Location: class init 3 errors

  • Cade the exit of the terminal?

  • sorry I thought I had put...

  • jack working

1 answer

3

Besides the fact that you do not close the string and neither the parentheses of the println, not finalize the line with ;, and not using access modifiers, the error is probably due to the fact that you name the file as poo1.java and write the class under the name of init.

In java, the name of the main class MUST be the same file name. Internal classes are allowed in the same file, but the main class must always have the same file name.

Another problem is the fact of not following the java conventions and write all the lower-case classes. Be aware of this, because following these rules is essential to write a code that is readable not only by you.

Recommended links for reading:

  • 1

    What’s the reason for the negative? If you really care about quality, let me know what’s wrong so I can improve. Negative and remain silent you are not helping the site or me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.