aspose file tools*
The moose likes Beginning Java and the fly likes question about inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "question about inheritance" Watch "question about inheritance" New topic
Author

question about inheritance

Ajay Kumar Rana
Greenhorn

Joined: Feb 27, 2008
Posts: 13
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

Joined: May 18, 2007
Posts: 341

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

Joined: Jan 28, 2008
Posts: 5575

hi ajay,

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

thanks & regards,
seetharaman
Santhosh Reddy
Greenhorn

Joined: Sep 25, 2006
Posts: 27
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

Joined: Aug 08, 2007
Posts: 202
only the methods are inherited, the variables they not are inherited, but are visibility for subclass but depends of type acess.


Brazil - Sun Certified Java Programmer - SCJP 5
http://www.camilolopes.com/ About Java - Update every Week.
Guide SCJP - tips that you need know http://blog.camilolopes.com.br/livrosrevistaspalestras/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about inheritance
 
Similar Threads
A question about Inner Class
Instance Variables & Class Variables
static variables
Inheritance | Static variable
static keyword over a block