I’m just learning Java… I have 2 custom classes. One is a Fraction and another is a Matrice that uses Fraction.
I’m using Eclipse, and created both classes from scratch via file->new->class (and default settings).
I’m wondering how can I use these two together in my main program? Like, when I try to add the classes to my project (it was unsuccessful but also) the Matrice class broke.
I also put the Fractions class (.class and .java) in a higher hierarchy of directories with no success (put Fractions in com.myfolder and Matrices in com.myfolder.myotherfolder and specified package com.myfolder and package com.myfolder.myotherfolder respectively).
So really, I have no idea what I’m doing here. I’m doing Java on my own, so I get stuck on a lot of the things like this. My question is, how do I:
- Make real classes I can use in the future (object classes or whatever you call them; like I would call a new instance of
Fraction/Matrice), - Make custom classes that extend other custom classes,
- Use my custom classes in a project.
I’ve googled it but had no luck. Many thanks in advance.
a) Just write them and probably provide a custom constructor. Then create instances using the
newkeyword.b) You used the correct keyword: extend(s):
c) Make sure the classes are on the classpath and use the
importkeyword to import them into classes that use them and are not in the same package: