Why does this java code not work if the method name is different from the class?

package tut;
import java.awt.Graphics;
import javax.swing.JFrame;


public class javaconcepts extends JFrame
   {
      public void paint(Graphics g)
      {
              g.drawOval(100,50,50,50);
      }

public javaconcepts()
   {
    setSize(600,400);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

   }
public static void main(String[] args)
   {
    javaconcepts guiWindow = new javaconcepts();
    guiWindow.setVisible(true);
   }    
}

Sorry for the very newbie, but I saw the code in a tutorial that I don't understand. The version in the text editor created an emoticon, but I just played the program to display a simple circle instead. I would really appreciate your help.

If I change the name "public javaconcepts ()" to something else, it gives me an error that says to make it type void. Changing it to enter void leads to the fact that the program does not execute what is in the brackets of "public javaconcepts ()".

I teach myself, so I don’t have a teacher to ask. Thank.

+4
source share
3 answers

public javaconcepts() "" (. ) - .

, ? java , . , , . - , - . :

access-modifiers return-type method-name(parameters)

?

- , new, .

: javaconcepts guiWindow = new javaconcepts();

: http://www.homeandlearn.co.uk/java/class_constructor.html

, . , Java . , . - .

[ new]

+4
0

. JLS-8.8. (),

SimpleTypeName ConstructorDeclarator , ; .

In all other respects, a constructor declaration looks like a method declaration that has no result ( §8.4.5 ).

0
source

All Articles