Hey everyone!
I made Address Book in Java, for this I have had to make three notepad files for three different classes. Can I put these three classes in one file and if yes, How can I ?
Aqsa Anum wrote:Hey everyone!
I made Address Book in Java, for this I have had to make three notepad files for three different classes. Can I put these three classes in one file and if yes, How can I ?
Yes, you can combine all that code into one file. They will have to be combined in the first file, which is the one that has the public class in it. The rule in Java is that you can have only one top-level public class in a file and that public class must have the same name as the file. So, you would edit your PersonInfo.java file and either copy/paste in the code that you have in the second and third files or you can type all the code in again manually. Another alternative would be to go to your OS command line and concatenate the second and third files to the first file. Obviously, you'd also need edit PersonInfo.java further to resolve errors about import statements.
Conversely, why would you want to do that? I can't imagine why a test class would need more visibility than the classes that it tests. Why would you give more prominence/importance to the test class over the "production" classes?
Aqsa Anum wrote:
Please tell me, what are these good reasons ?
Thank you
By making the TestClass as public and the others non-public, you are implying that TestClass is more important than the others. Why would a class that is used for testing be more important than the classes that are being tested?
Aqsa Anum wrote:
Please tell me, what are these good reasons ?
Thank you
By making the TestClass as public and the others non-public, you are implying that TestClass is more important than the others. Why would a class that is used for testing be more important than the classes that are being tested?
You said right, there are two other classes too, which are more important than testing class. Then Different notepad files for each class looks fine.
But if we want to do it in NetBeans, How we will code it ? Would there also be distinct files for each class ?
Aqsa Anum wrote:
Please tell me, what are these good reasons ?
Thank you
By making the TestClass as public and the others non-public, you are implying that TestClass is more important than the others. Why would a class that is used for testing be more important than the classes that are being tested?
Aqsa Anum wrote:
Please tell me, what are these good reasons ?
Thank you
By making the TestClass as public and the others non-public, you are implying that TestClass is more important than the others. Why would a class that is used for testing be more important than the classes that are being tested?
The order in which the classes appear in the source file makes no difference. The fact that one is public and the others are not makes the public one appear to be more important than the others.
Post by:autobot
This one time, at bandcamp, I had relations with a tiny ad.
a bit of art, as a gift, the permaculture playing cards