• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Question on Default Access Modifier  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I have defined these two classes under same java project in Eclipse IDE with no package. Above two class are having default classes. class Course is also having a instance variable courseName with default access. So when we try to compile the Entry class it will give the errors while accessing the instance variable courseName on Line 6 and 7.
Q) As both the classes are having default access modifier. class Course is not visible to class Entry, then why we do not get any compilation error while creating the object of class Course on line 5?
 
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch!

To get help, I would advice you to port your question in the appropriate forum. It is also worthwhile to have a look at http://www.coderanch.com/how-to/java/HowToAskQuestionsOnJavaRanch

A defualt access modifier or package access modifier means that any member is accessible only within the declared package. Try putting them in some package and try accessing it.

 
author
Sheriff
Posts: 23588
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Moving this topic to the beginner Java forum
 
Marshal
Posts: 60130
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both classes compiled and could be executed from the terminal. I think what is happening in Eclipse is that you are putting them into different folders somehow. IDEs do not usually work well with the unnamed package, so you should avoid it.

I have added code tags, which you should always use, and don't they make the code look better.
And welcome again
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!