Java apprentice Java apprentice - 1 year ago 71
Java Question

error: constructor cannot be applied to given types

Here is my code:

public class eggs {

static int pick;

public eggs (int newPick) {
pick = newPick;

This part works without problems.

eggs egg = new eggs();

This is the part I'm having problems with, when I compile the class with this in I get the error in the title.

Answer Source

A constructor must have the same name as the class:

public class Eggs { 
    private int pick;

    public Eggs (int newPick) {
        pick = newPick;

    public Eggs () {

Note that I also capitalized your class to Eggs in accordance with the naming standard.

To address the comments by @Elliott, I made the field non static and private. Also, I defined an empty constructor. Note that Java will only generate a default empty constructor in the event that nothing else be defined, which is not the case for your code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download