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

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

package LinkedList; class ListNode { protected int value; String name; } package LinkedList; public class List { ListNode header; protected ListNode sentinelNode; public List() { header = new ListNode(); 1) header.value = 10; 2) header.name = "brad"; sentinelNode = new ListNode(); } } package LinkedQueue; class Queue extends LinkedList.List { public Queue() { 3) header.value = 20; 4) sentinelNode.value = 30; } }

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!