5. For the next three problems, consider the following class: 1 // Represents a university student, 2 public class Student ( 3 private String name; private int age; 9 10 11 public Student (String name, int age) ( this.name name; this.age - age; public void setAge(int age) { this.age age; 12 13 14) Also consider the following partial implementation of a subclass of Student to represent undergraduate students an a university: ... public class Undergraduate Student extends Student { private int year;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Number 5
Section 9.2: Interacting with the Superclass
4. Explain the difference between the this keyword and the super keyword. When should each be used?
5. For the next three problems, consider the following class:
1 // Represents a university student.
2 public class Student (
private String name;
3
private int age;
4
5
6
7
8
9
public Student (String name, int age) (
this.name = name;
this.age age;
10
11
12
13
14 )
Also consider the following partial implementation of a subclass of Student to represent undergraduate students at
a university:
}
public class Undergraduate Student extends Student {
private int year;
public void setAge(int age) {
this.age age;
}
}
}
Can the code in the Undergraduate Student class access the name and age fields it inherits from Student? Can
it call the setAge method?
6. Write a constructor for the Undergraduate Student class that accepts a name as a parameter and initializes the
UnderGraduate Student's state with that name, an age value of 18, and a year value of 0.
}
7. Write a version of the setAge method in the Undergraduate Student class that not only sets the age but also
increments the year field's value by one.
8. Consider the following two automobile classes:
public class Car {
public void m1() {
}
public void m2 () {
649
System.out.println("car 1");
System.out.println("car 2");
public String toString() {
return "vroom";
Transcribed Image Text:Section 9.2: Interacting with the Superclass 4. Explain the difference between the this keyword and the super keyword. When should each be used? 5. For the next three problems, consider the following class: 1 // Represents a university student. 2 public class Student ( private String name; 3 private int age; 4 5 6 7 8 9 public Student (String name, int age) ( this.name = name; this.age age; 10 11 12 13 14 ) Also consider the following partial implementation of a subclass of Student to represent undergraduate students at a university: } public class Undergraduate Student extends Student { private int year; public void setAge(int age) { this.age age; } } } Can the code in the Undergraduate Student class access the name and age fields it inherits from Student? Can it call the setAge method? 6. Write a constructor for the Undergraduate Student class that accepts a name as a parameter and initializes the UnderGraduate Student's state with that name, an age value of 18, and a year value of 0. } 7. Write a version of the setAge method in the Undergraduate Student class that not only sets the age but also increments the year field's value by one. 8. Consider the following two automobile classes: public class Car { public void m1() { } public void m2 () { 649 System.out.println("car 1"); System.out.println("car 2"); public String toString() { return "vroom";
Expert Solution
steps

Step by step

Solved in 6 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY