compilation error java (javac) [closed]

-1

I have a file "poo1.java":

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");
                }
        }
}

When I compile the poo1.java (javac poo1.java) into 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: can not find symbol Pen bic1 = new Pen (); ^ symbol: class Pen location: class init   poo1.java:5: error: can not find symbol Pen bic1 = new Pen ();                           ^ symbol: class Pen location: class init 3 errors

    
asked by anonymous 15.10.2018 / 01:50

1 answer

3

In addition to the fact that you do not close the string and the println , do not end the line with ; , and do not use access modifiers, the error is probably due to the fact that you name the file as poo1.java and write the class with the name of init .

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

Another problem is that you do not follow java conventions and write whole-lower-case classes. Be aware of this, because following these rules is essential to writing a code that is readable not just by you.

Recommended reading links:

15.10.2018 / 02:11