Here is a doubt. I am new to java and coding in general and this seems a common doubt among others but couldn't find relevant explanation. As far as I understand only objects within a class can use class_name as datatype.Then how is it possible to create object called head of class Node in another class LinkedIist on
Line 14?
#Linkedlist
7 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @void crow! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
The class uses the default modifier and is therefore package private meaning that only classes in the same package can use said class. Since the class LinkedList is in the same package it can use the class Node. Classes outside this package can't use it.
Is it necessary to use a package?what if we don't use any package?how can we make object head in that case?
No package is still a package, so your classes would be in the same package and able to use each other
- Yes, even if you don't define the package, the class still is in one, in that case it would be default no-name package
- Then the class will land in the default package but it will still be inside a package
- Not applicable since the second scenario does not exist