Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1- Provide 2 reasons why object-oriented programs run more slowly than procedura

ID: 3790033 • Letter: 1

Question

1- Provide 2 reasons why object-oriented programs run more slowly than procedural programs.

2-

You are given the following declarations in Java (you should assume that each class would be placed in a different file):

Answer the following yes/no questions about the above code and for each answer explain why you answered as you did:

1- Is it legal to access the value variable in statement 1?

2- Is it legal to access the name variable in statement 2?

3- Is it legal to access the header variable in statement 3?

4- Is it legal to access the sentinelNode variable in statement 4?

5- Is it legal to access the value variable in statements 3&4 (even if you answered no to either statement 3 or 4, assume that you had answered yes and consider whether based on a "yes" answer, if value would be accessable)? Hint the answer and reason is the same in both cases.

package LinkedList class ListNode f protected int value; String name; package LinkedList; public class List List Node header protected ListNode Sentinel Node; public List header new ListNode header value 10 1) 2) header name brad. sentinel Node new istNode() L package LinkedQueue class Queue extends LinkedList.List public Queue() header value 20 3) sentinel Node. value 30

Explanation / Answer

Please let me know in case of any issue.

Reason of slower :
1. The inheritance mechanism means that object instances contain vtables which can be a small source of slowness. The method call is reconciled with the correct code by means of a table look-up.

2. the message sending process means that more work has to be done at runtime to match the message to the code.

1.
   Is it legal to access the value variable in statement 1?
   No, 'value' defined in ListNode is protected member. It can be
   only accessible directly by subclasses.

2- Is it legal to access the name variable in statement 2?
   Yes. 'name' is default memeber of ListNode .If all these classes are defined in same package, then default members are accessible inside same package.

3.
   3- Is it legal to access the header variable in statement 3?
   No, 'header' is the default memeber of LinkedList class. and
   LinkedQueue class is defined in different package, so default members
   are not inherited.

4- Is it legal to access the sentinelNode variable in statement 4?

   Yes. 'sentinelNode' is protected member of LinkedList class, so it is
   inherited in subclasses.

5- Is it legal to access the value variable in statements 3&4
   No. 'value' is protected member of ListNode class. It will only directly accessible inside in same class(ListNode) and its child classes.