Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is Importing extending

 
RajTilak Sivaluri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to learn clearly about importing but now i am clearly confused what i am confused is that when i try to write as this it is working




Now my compiler is not producing any error but my doubt is if this is right my class is actually a subclass to class ArrayList .
which means it is no more a super class. And the other doubt is actually importing a class do mean that we are making our class a subclass to the imported class . Do post your comments
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RajTilak Sivaluri wrote:
Now my compiler is not producing any error but my doubt is if this is right my class is actually a subclass to class ArrayList .
which means it is no more a super class

I don't get this sentence. If another class extends your class, then your class will be a super class to that extending class.
RajTilak Sivaluri wrote:
And the other doubt is actually importing a class do mean that we are making our class a subclass to the imported class . Do post your comments

Nope, import guides the compiler where to check the class which you've imported.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, Welcome to JavaRanch!
 
RajTilak Sivaluri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:
RajTilak Sivaluri wrote:
Now my compiler is not producing any error but my doubt is if this is right my class is actually a subclass to class ArrayList .
which means it is no more a super class

I don't get this sentence. If another class extends your class, then your class will be a super class to that extending class.
RajTilak Sivaluri wrote:
And the other doubt is actually importing a class do mean that we are making our class a subclass to the imported class . Do post your comments

Nope, import guides the compiler where to check the class which you've imported.


What i was exactly saying was I created a class Myclass right !! but instead of using the import statement i extended the ArrayList class which i intended to use hence why why shouldn't i say that Myclass is a subclass to class ArrayList . Because i have done all the things to make it a subclass
 
RajTilak Sivaluri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Yup Abhiram Thankyou
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elaborating on Abimaran's reply to the second doubt:

In the code you have provided-


You must have observed that you never defined the class ArrayList in your source code, instead with the above syntax- java.util.ArrayList- you are using the ArrayList in the java.util package provided by the Java API. These java classes are organized in different packages depending on their functionality. There's another way as well to import the classes:


In the above code- you need not use java.util.ArrayList (which is called fully qualified name of the class) everytime you would want to refer to the ArrayList. Because the import you have used tells the compiler where to check for the ArrayList class.

Extending- is what makes one class super class of another/sub class of another class.

This is how you create a SubClass- SuperClass relationship (not considering Interfaces here as it might be confusing if you are starting with).

Also lets see a case where we are using importing and not Extending:



We can also use wildcard(*) in the import statement:



which indicates that you can be referring to any class from the package- java.util.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RajTilak Sivaluri wrote:
What i was exactly saying was I created a class Myclass right !! but instead of using the import statement i extended the ArrayList class which i intended to use hence why why shouldn't i say that Myclass is a subclass to class ArrayList . Because i have done all the things to make it a subclass


I don't understand, what you've said above.

And My Name : Abimaran.
 
RajTilak Sivaluri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extending- is what makes one class super class of another/sub class of another class.



This exactly the answer which i am looking for
 
RajTilak Sivaluri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mohammad Sanullah .

@Abhiram : next time when i post my query i will try to elaborate it clearly this was my first post so could not make it clear
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RajTilak Sivaluri wrote:...@Abhiram : next time when ...


You got his name wrong again
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohamed sanaullah wrote: . . . You got his name wrong again
Thank you for noticing. It can cause a lot of annoyance when you copy somebody's name wrongly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic