Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This class is created in the same file as Student. This is typically not common practice but I thought it was a good idea to see both classes in the same file.
- class Person{
- private String name;
- public Person(String n){
- name = n;
- }
- public String toString(){
- return name;
- }
- }
- public class Student extends Person{
- private int id;
- public Student(String n,int i){
- super(n);
- id = i;
- }
- public String toString(){
- return super.toString() + " ID: " + id;
- }
- public static void main(String[] args){
- Student s = new Student("Nancy", 55);
- System.out.println(s instanceof Student);
- System.out.println(s instanceof Person);
- System.out.println(s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement