• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Package Inheritance

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,

i have a doubt on package concept.

That is, i have created the package in one directory and saved it.
Then, i have created the another one program and i tried to extend the
class which resides on the package.
but the package in one directory and the program or class is in another directory, and i used to extend that package class it displays some error.

CAN I DO That.

example:
********

package samp
{
class A
{

***
some STMT;
***

}
}

the above package saved in the directory called \vijay\

if i use the another one pgm by extending the A class it displays error.
i want to know the reason why it displays.



and also
in package class i declared the protected type data.

if i access that from the outside of that class, this also
displays the error as "cant access the data".

this also i want to know the reason why we cant access the
protected type on extended class?




Thanks & Regards,

Vijay
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your description is not so clear, so I hope I'm explaining what you're asking.

Yes, you can create a package in one directory with a class in it, and write another class somewhere else (in a different program) that extends the class, as long as you put the first one on the classpath correctly.

What is "some error"? If you get an error, please copy & paste the exact error message in your post - the more precise you are, the better we can help you. Just saying "it displays some error" is too vague.

Things that are protected are accessible in subclasses and in classes in the same package.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi vijay,

Can you post up your class implementation code? It might have something to do with the package accessibility.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic