• Support PF! Buy your school textbooks, materials and every day products Here!

JAVA: Object Oriented Programming Basics: Problem: class, interface, or enum expected

  • Comp Sci
  • Thread starter kloong
  • Start date
  • #1
36
0
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

What i tried to do:
//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 buid it, it keeps giving me the class, interface, or enum expected error. Why is that?
 

Answers and Replies

Related Threads on JAVA: Object Oriented Programming Basics: Problem: class, interface, or enum expected

Replies
9
Views
2K
Replies
9
Views
2K
  • Last Post
Replies
8
Views
494
  • Last Post
Replies
4
Views
813
Replies
9
Views
8K
Replies
1
Views
2K
  • Last Post
Replies
6
Views
627
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
4
Views
2K
Top