• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on Default Access Modifier  RSS feed

 
Mahesh Gawade
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?
 
Joe Harry
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.

 
Henry Wong
author
Sheriff
Posts: 23295
125
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
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!