``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
OCJP-90%,OCPWCD-95%
Hama Kamal wrote:what is the difference btw importing and extending a class interms of Modifiers?
but can we import it without extending ?
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Ikpefua Jacob-Obinyan wrote:Hello Hama Kamal,
I have a 'pop-quiz' that might even lead to figuring out the answers to your doubts... it is as follows;
-What is the use of import statements?
-Why do we extend classes?
Let me know what you think, and if this does not clarify your doubts we can continue from there...
Regards Ikpefua.
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
sagar shroff wrote:
HI,
You are having some misconception, i will make you understand.
Classes with default access is available or accessible only to classes within same package where as in the case of public it is accessible to all the classes in java Universe.
example.
-----------
package p;
class A
{
}
Now class A is having default so it can only be accessible to classes in package P
So in order to use class A or if you wanna make a reference to it in your class then you need to either use its fully qualified name or
you simply import it.
by importing you give a short name to the fully qualified name
import java.p.A;
class Your_Class
{
A obj=new A();
}
if you had not imported then you would have to use fully qualified name i.e
class Your_Class
{
p.A obj=new p.A();
}
Both the examples are legal providing they are in same package p
In case of public modifier to a class it is available to whole Java Universe.
I hope i helped You..
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
OCJP-90%,OCPWCD-95%
Hama wrote:
we use import statements so that we can import classess from different packes and make objects of them in our class and later to access it's methods or instance variables
Hama wrote:so what i understand is extending is inheritance but importing is not ,, am i right?
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
Tommy Delson wrote:
Below is a modified version of Hama Kamal code. Have a review, answer each question and see if you answer them correctly and understand why.
Next try to test and run the code and see how they work. If they're not working, what change do you make to make them work? Will follow up with explanation in details
later if you're not clear.
Just a little challenge for a review...this type of scenario required knowledge of inheritance, access modifiers, package etc.
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
Ikpefua Jacob-Obinyan wrote:
Hama Kamal wrote:what is the difference btw importing and extending a class interms of Modifiers?
but can we import it without extending ?
The first question is somewhat 'ambiguous', because a specific scenario will make one explain better, now the second question(quite specific) has a direct answer 'YES'. This is because an import statement and inheritance(extends) are two different things, However it is important to understand both concepts.
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
Ikpefua Jacob-Obinyan wrote:Hello Hama,
can you try everything you have just asked by coding?...Yes I mean write test programs, create packages, declare classes inside the packages, carryout imports and extends of classes between packages with different access modifiers and write down your findings, "personal experience is the best teacher".
I hope this helps.
Regards
Ikpefua.
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
Hi Tommy ,, thanks for your test, and check my answer a bove
this class can not run because class tea can't extend class Drink Since they are in different packages and class Drink is not public and hence all of the below fails!
OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
Consider Paul's rocket mass heater. |