NVOAssignment3 Problem Answer.docx - COMP 2150-001 Nhan Vo Assignment 3 Answer Fall 2019 Question3(5 marks Describe the difference between method

NVOAssignment3 Problem Answer.docx - COMP 2150-001 Nhan Vo...

This preview shows page 1 - 2 out of 4 pages.

COMP 2150 -001 Assignment 3 Answer Fall 2019 Nhan Vo Question3 (5 marks) Describe the difference between method matching and method binding. Method matching: In case of method overloading, method matching is required to decide which method to be invoked. At compile time, the declared type of reference variable decides which method to match. At compile time according to parameter type, number of parameters, and order of the parameters the compiler finds a matching method. Method Binding: In case of method overriding, method is required to decide which method to be invoked. A method may be implemented in several subclasses. The Java Virtual Machine (JVM) dynamically decides which method to be invoked. It binds the implementation of the method at runtime. It takes the method based on the actual class of the object referenced by the variable. Question 4 (15 points) Demonstrating the Static binding behavior: The picture below is captured from D.java to demonstrate the static binding. In the main method of class D, there are 4 objects are created: Object ‘a’ has reference variable type ‘A’ and object type is also ‘A’, Object ‘b’ has reference variable type ‘B’ and object type is also ‘B’, Object ‘c1’ has reference variable type ‘B’ and object type is ‘C’, Object ‘c2’ has reference variable type ‘C’ and object type is also ‘C’, Furthermore, class ‘B’ is subclass of class ‘A’, and class ‘C’ is subclass of class ‘B’ In class ‘B’, there is a static method name ‘mb2()’, and in class ‘C’ there is also a static method name ‘mb2()’. They both have same signature.
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 4 pages?

  • Fall '08
  • Staff

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes