• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Doubt in Overriding Static Method....?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the follwing is true about static modifier.




A.static can be applied to : instance variables, methods,
code Segments and classes.

B.a static method cannot be overridden.

C.inner classes can be both static & private.

D.a static reference cannot be made through non static
method or code block.

E.abstract & static both can be applied together to a
method.



One of the answer is B.

How is it ? Check this program�����..No error nothing�Compiles and run..

class A
{
static void m()
{
System.out.println("In super class");
}
}

public class StaticOverride extends A
{
static void m()
{
System.out.println(" In Subclass");
}

public static void main(String args[])
{
StaticOverride ob = new StaticOverride();
m();
}
}
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hie Manoj,


Try to find out the difference between "Overriding and Redefining a method",
you will get your answer.

Tell me, don't you even think
"Static methods can't be overridden"


BTW: What are other correct answers you figure out?

Regards,
cmbhatt
[ April 11, 2007: Message edited by: Chandra Bhatt ]
 
Manoj Mani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C & D
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Overriding is an object-oriented feature and is connected with class families and polymorphism. Static members are theoretically outside the bounds of pure OO. Read up on this and you will see light!
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i believe you are looking for this

http://faq.javaranch.com/view?OverridingVsHiding
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
answer is : A,B,C true
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jack,

Please read the options carefully,

B,C are only the correct answers.

A is wrong!

Option D is confusing!



Please anybody make it clear!!!


cmbhatt
[ April 11, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The wording of option D is confusing.

If it means you can't call a static method from within a non-static method or code block, that is wrong.
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic