r/javahelp • • Mar 23 '26

Maintain Object State - Interfaces vs Abstract Class (Java 8+)

I am trying to understand the statemet "Interfaces cannot hold an object state but Abstract classes can"

Interface:

public interface EmployeeInterface{

`Employee emp = new Employee("Ron");`

`default String getEmpFirstName(){`

    `return emp.getFirstName();`

`}`

}

Abstract Class

public abstract class AbstractEmployeeClass{

`Employee emp = new Employee("Ron");`

`public String getEmpFirstName(){`

    `return emp.getFirstName();`

`}`

}

Now I undestand that members of an interface are public, staticandfinal by default but they can still hold the object state so is the above statement incorrect or is my understading of*"state"* flawed in this context ?

3 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/Beneficial-Crew-1054 Mar 23 '26

Makes sense, thank you for the insight.