2 min read•july 11, 2024
Milo Chang
Example: 🔍
public class Student
{
private String name;
public Student (String newName)
{
name = newName;
}
public void setName (String newName)
{
name = newName;
}
public String getName ()
{
return name;
}
}
This code will not work: 🚫😱
public class Athlete extends Student
{
public void printName ()
{
System.out.println(name); // THIS WILL NOT WORK
}
// There may be instance variables, constructors, and other methods not
// shown.
}
© 2024 Fiveable Inc. All rights reserved.