Java: Object Oriented Programming: Problem: class, interface, or enum expected?

This is the question:

public class Postman {

private String Name;

private int Age;

}

How you can update and retrieve the private variables Name and Age from another class Worker.

public class Worker {

//An object a is created from class Postman

And this is what i came up with.

//Postman.java

public class Postman{

private String name;

private int age;

}

//constructor

public Postman(String name, int age){

this.name=name;

this.age=age;

}

//accessors

public String getName(){

return name;

}

public int getAge(){

return age;

}

//worker.java

public class worker{

public static void main(String args[]){

Postman employee = new employee("Tom the postman", 55);

System.out.println(employee.getName());

System.out.println(employee.getAge());

}

}

But when i build them, i keep getting class, interface, or enum expected. Why is that?

thanks.

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 Q2A.ES - All rights reserved.