java - Having a lot of trouble; illegal start of expression -
i'm new computer programming -- having literally started course little under 6 weeks ago -- , i'm having trouble illegal starts of expressions in netbeans.
the whole code goes follows(since don't know start):
public class employees { /** * @param args command line arguments */ public static void main(string[] args) { // todo code application logic here public class employee //properties private string name; private string id; private string salary; //constructor public employee (string name, string address, string dob) { this.name = name; this.id = id; this.salary = salary; } //method print details on employees public void printdetails() { system.out.println("employee name: " +this.name); system.out.println("id: "+ this.id); system.out.println("annual salary: " + this.salary); } } }
you cannot declare class (public class employee) within method declaration (public static void main(string[] args) {).
best move declaration of class employee own file (employee.java). if don't want move different file, can move end of existing file. have declare private instead of public then.
or can make 1 class this:
public class employees { /** * @param args command line arguments */ public static void main(string[] args) { employees employee = new employees("name", "address", "dob"); employee.printdetails(); } //properties private string name; private string id; private string salary; //constructor public employees (string name, string address, string dob) { this.name = name; this.id = id; this.salary = salary; } //method print details on employees public void printdetails() { system.out.println("employee name: " +this.name); system.out.println("id: "+ this.id); system.out.println("annual salary: " + this.salary); } }
Comments
Post a Comment