How do Imports work?
Posted: Fri Jun 02, 2023 8:22 pm
Hi, I am on chapter 4 learning about packages and imports right now and I just had a few questions.
So, for example, on page 60 where it states "Important points about the import statement" and under point #4, it states something along the lines of "java.lang is imported automatically into ALL THE CLASSES". The statement "all the classes" is just throwing me off a bit
I understand that imports basically just take the classes from different packages (or even the same packages) and basically make it known to the compiler that we may or may not be using aspects of other packages/classes in this program
But when the book says "all the classes" it makes it seem like every class in the src will have an import, however, I thought it would be more like how packages are made (which is declaring the package file once at the top of the program)
So I just wanted some clarification on how imports work and when are where they are declared, if you don't mind
So, for example, on page 60 where it states "Important points about the import statement" and under point #4, it states something along the lines of "java.lang is imported automatically into ALL THE CLASSES". The statement "all the classes" is just throwing me off a bit
I understand that imports basically just take the classes from different packages (or even the same packages) and basically make it known to the compiler that we may or may not be using aspects of other packages/classes in this program
But when the book says "all the classes" it makes it seem like every class in the src will have an import, however, I thought it would be more like how packages are made (which is declaring the package file once at the top of the program)
So I just wanted some clarification on how imports work and when are where they are declared, if you don't mind