i'm new java , i've got package interfaces. each interface has number of imports types used in interface declarations.
// myinterface.java... package a.b.c.interfaces; import java.math.bigdecimal; import java.util.list; import java.util.set; public interface myinterface() { ...
then i've got package models, , inside of it, i'm attempting create class implements myinterface()
.
// myimplementation.java... package a.b.c.models; public class myimplementation implements myinterface {...
i have 2 questions:
- does
myinterface()
need importedmyimplementation()
? if not, need linked manually during compilation? - if
myinterface()
imported, necessary import types interface requires, or import ofmyinterface.java
take care of this?
imports in java way of telling compiler when write myinterface
mean a.b.c.interfaces.myinterface
. possible write java code without using imports extremely verbose , looks messy.
you need import type want use not in same package class you're writing or in java.lang
since myinterface
in a.b.c.interfaces
, myimplementation
in a.b.c.model
need import it.
you need import classes myinterface
using if you're writing type anywhere in code - , since you're implementing interface need write types in method declarations. there no way of using same imports class in java.
here example of usage of types don't need import them:
usesbiginteger.java:
import java.math.biginteger; public class usesbiginteger { public biginteger get() { return biginteger.ten; } }
main.java
public class main { public static void main(string[] args) { usesbiginteger use = new usesbiginteger(); system.out.println(use.get()); } }
the reason don't have import java.math.biginteger
here never write biginteger
anywhere don't need tell compiler mean - pass return value usesbiginteger.get()
along , compiler knows that java.math.biginteger
.
if want keep reference biginteger
need import though:
main.java
import java.math.biginteger; public class main { public static void main(string[] args) { usesbiginteger use = new usesbiginteger(); biginteger = use.get(); system.out.println(it); } }