Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings to all CodeProject members ,
i am new to Java ,and i would like to ask why my Constructor and show() method doesn²t work ?
Where is my mistake ?



Java
import java.io.*;

 class Salarie
  {
   String name;
   String company;
   int sailary ;
  }

 public Sailary(String n, String e, int s)
  {
   name=n;
   company=e;
   sailary=s;
  }

 public void show()
  {
   System.out.println(nom+" "+company+" "+sailary); 
  }
  

public void main(String args[])
    {
      sailary sa=new sailary("martin","ETV",1500);
      p1.show();
    }
Posted

If you want to write a Java program then you must know and use the correct Java syntax.
Java
import java.io.*;

class Salary
{
   String name;
   String company;
   int salary ;


 public Salary(String n, String e, int s)
  {
   name=n;
   company=e;
   salary=s;
  }

  public void show()
  {
   System.out.println(name+" "+company+" "+salary);
  }


  public static void main(String args[])
    {
      Salary sa = new Salary("martin","ETV",1500);
      sa.show();
    }

}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Sep-14 11:30am    
5ed.
—SA
CPallini 3-Sep-14 12:31pm    
Thank you, Sergey.
voronitski.net 3-Sep-14 17:58pm    
Thank you
CPallini 4-Sep-14 1:55am    
You are welcome.
i think you have to read the basic java syntax before starting the coding.there is lot of EBOOKS available in the internet.specially how to create the class and how to create the methid inside the class etc.
example

class Salary
{
String Name;
String Company;
int salary; // Normally salary is not a int it should be either double or float


// Constructor of Salary Class // no return type, must be Class name
public Salary (String a, String b, int c)
{
this.Name = a;
this.Company = b;
this.Salary =c;

}

public void show()
{
System.out.println(Name + "\n" + Company + "\n" + Salary);
}

public static void main(String [] args)
{

//passing the values into the constructor same data type and number of parameter must same

Salary s = new Salary("Nuke"."ABC",12000);
s.show();


}

}
 
Share this answer
 
Largely because you spelled everything differently. You used Salarie for your class, Sailary for the constructor, and sailary when trying to instantiate an object. You also spelled other bits wrong in your show method. A bit more care in typing would go a long way.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900