Java Programming

timer Asked: Nov 20th, 2016

Question description

Please use JGrasp.


COP 2800, Java Programming, Fall B 2016 Due date: November 27th, 2016 midnight (11:59pm). Assignment 5(10 points): From Textbook page 424 use Listing 11.6 Add a class that extends Object and a class that extends the new class you just created. Add the code to create objects from the new classes you created which will print what each class is. These new classes can be animal, vegetable or mineral, in other words just two classes that it makes sense for the second class created to extend from the first class extend. Hopefully you will find this an easy assignment for Thanksgiving week, and please contact me if you do not understand my instructions. Happy Thanksgiving. At the beginning of the program add the following comments. //Filename //Written by //Written on //Assignment number //Description of program Purpose: Create a java program from detailed directions. Ability to: Follow established programming conventions for writing java programs Able to extend an Object and a class Able to create objects from the classes created. Upload your .java file in the Assignment 5 folder under “Assignments”.
Listing 11.6 1 public class DynamicBindingDemo { 2 public static void main(String[] args) { 3 m( new GraduateStudent()); 4 m( new Student()); 5 m( new Person()); 6 m( new Object()); 7} 8 9 public static void m(Object x) { 10 System.out.println(x.toString()); 11 } 12 } 13 14 class GraduateStudent extends Student { 15 } 16 17 class Student extends Person { 18 @Override 19 public String toString() { 20 return "Student" ; 21 } 22 } 23 24 class Person extends Object { 25 @Override 26 public String toString() { 27 return "Person" ; 28 } 29 } Student Student Person java.lang.Object@130c19b Method m (line 9) takes a parameter of the Object type. You can invoke m with any object (e.g., new GraduateStudent() , new Student() , new Person() , and new Object() ) in lines 3-6). When the method m(Object x) is executed, the argument x 's toString method is invoked. x may be an instance of GraduateStudent , Student , Person , or Object . The classes GraduateStudent , Student , Person , and Object have their own implementations of the toString method. Which implementation is used will be determined by x 's actual type at runtime. Invoking m(new GraduateStudent()) (line 3) causes the toString method defined in the Student class to be invoked. Invoking m(new Student()) (line 4) causes the toString method defined in the Student class to be invoked; invoking m(new Person()) (line 5) causes the toString method defined in the Person class to be invoked; and invoking m(new Object()) (line 6) causes the toString method defined in the Object class to be invoked. Matching a method signature and binding a method implementation are two separate issues. The declared type of the reference variable decides which method to match at compile time. The compiler finds a matching method according to the parameter type, number of parameters, and order of the parameters at compile time. A method may be implemented in
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors