• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about inheritance

 
Ajay Kumar Rana
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to know when we extend a class then Do the variables are also inherited to the subclass or not?
what i exactly want to know is if

class A{}
class B extends A{}

then will the variables of class A be present in class B or not (i want to know about both types of variables static and non-static).Explain.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a class extends some other class i.e. inherits some other class, then the member of parent class invariably become part of sub class.
But, the visibility of the members depends on the access specifiactions e.g public, protected, private ...

Same is true for static variables. But, as only one single copy of static variables exists across the application. So, the same copy is shared for the sub classes.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ajay,

variable is available (static & non-static untill they are not marked as private) in subclass..

thanks & regards,
seetharaman
 
Santhosh Reddy
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
every member of a super class(may be variable or a method) is a member of subclass untill they are visible to subclass.
 
camilo lopes
Ranch Hand
Posts: 202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
only the methods are inherited, the variables they not are inherited, but are visibility for subclass but depends of type acess.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic