• 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

Question on inheritence

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is inheritence of a class confined only to the non-static members functions of a class or static functions too?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static members are inherited, but static methods cannot be overridden.

You should write some code to test this.
 
Jitender kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could not find this statement in K&B book and so, I thought I would point out. Sorry, if I overlooked into the book.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi jitender,

for more clarification, a small example :

package mypackage;

class Parent
{
//Parent(String str){}
public static void XYZ(){ System.out.println("Parent XYZ");}

}

public class Child extends Parent
{
public static void XYZ(){System.out.println("Child XYZ");}
public static void main(String[] args)
{
Parent ch = new Child();
ch.XYZ(); // Special Line
}

}

if u change the statement at special line

1. Parent ch = new Child();
ch.XYZ(); // Special Line

Output is ----> Parent XYZ

2. Parent ch = new Child();
Parent.XYZ(); // Special Line

Output is -----> Parent XYZ

3. Child ch = new Child();
Child.XYZ(); // Special Line

Output is -----> Child XYZ

try some more combinations, so that u can understand better. hope it helps.


Chandu.
 
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