• Post Reply Bookmark Topic Watch Topic
  • New Topic

extending abstract class in a package  RSS feed

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
i am new to java programming, i was going through abstract classes and packages, and i faced this problem.
i had created an abstract class in a package. i am extending that abstract class by another concrete class in same package.i am able to compile the abstract class, but i am not able to compile concrete class. i am getting "Cannot Resolve Symbol" error.
i tried to change the classpath to current directory also. i tried to compile file using javac -classpath . <filename.java> too. but nothing worked out for me.
following are my java code. can any body tell me what is the problem and solution.

Person.java
package foo;
public abstract class Person
{
private String name;

public String getName() { return this.name;}

public void setName(name){ this.name=name; }
}

Employee.java
package foo;
public class Employee extends Person
{
private int empID;

public int getEmpID() { return empID; }

public void setEmpID(empID) {this.empID=empID;}
}

Thanks in Advance
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey ... Before coming up to the forum just read the study material carefullly.



Here you have not mentioned about the type (the method signature in incomplete).

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all in your Person.java
public void setName(name){ this.name=name; }
It should be:
public void setName(String name){ this.name=name; }

In your Employee.java
public void setEmpID(empID) {this.empID=empID;}
It should be:
public void setEmpID(int empID) {this.empID=empID;}

Moreover:
It's legal, but I dont see the functionality of abstract class in your person class.
Your person class functions like other concrete class.
The get/setName with no body content would be better and then these abstract methods will be implemented in your concrete class (Employee.java)
 
KRK Gowda
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
that was a typing error.i tried to add an abstract method and tried to implement in concrete class. but still i am not able to compile concrete class
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your latest code (using code tags to make it more readable) plus the exact error messages you are getting and people will be more able to help you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!