Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
java programming using eclipse, why must we create a different tabs/pages for each class?
We're using eclipse at school for our Java codes and I was wondering why we need to put different classes on new tabs and link them using packages.....um, can't we just put them on one page? Like in C++? Or is our teacher confusing us and can we in fact put our entire program with all its classes on one page? or is each class in Java supposed to be in a different file or something?
and while I'm asking on here, how do we create obects for classes in other files? is it the same way we would for C++? like, treat it as if it were in the same file?
2 Answers
- Anonymous1 decade agoFavorite Answer
Yes as long as they are compiled together and inside the same package you reference classes in other files as if they were in the same file.
class Main{
public square = new Square();
}
class Square{
}
have you ever looked inside a REAL java program? Outside of the code you do for early assignments, you would never want to have all your code in a single class file. It makes it a pain to edit and manage. Furthermore most of Eclipse's really cool IDE features depend on the 1 class per file structure (inner classes are an exception, but its still one class, just with helper classes nested inside)
- 53MalePrisonLv 41 decade ago
Your teacher is right. Each class in java is a different file with .java exception. When compiled, it creates a .class file.
Being said that, there you can create inner classes in java. But that is probably advanced concept. Just follow your teacher.
Good luck!