• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overridding

 
Raj Gahalot
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Can we override static methods?

2. What is top level class and what are the modifiers we can use in top level class?
 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raj Saini:
1. Can we override static methods?

Yes, we can override static methods untill it's not declared private.
2. What is top level class and what are the modifiers we can use in top level class?

Top class is the class in which we can nest other classes

class Top_level
{
class Top_level1
{
}
}
it is either public or by default has no access specifier.
[ October 17, 2008: Message edited by: Pawan Arora ]
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well there is a huge confusion with everybody about static method overriding.

well actually static methods are hidden and not overridden.

see this link
 
sweety sinha
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

originally posted by Pawan Arora:
Yes, we can override static methods untill it's not declared private
.

No we cannot override static method we can only redefine it.




originally posted by Pawan Arora:
Top class is the class in which we can nest other classes

top level nested class is the static member class of a class .
[ October 17, 2008: Message edited by: sweety sinha ]
 
subhasish nag
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pawan,
we can't override Static methods.It's just hidding .
Try this
class P{
static void a(){System.out.println("in P");}
}

class C extends P{
static void a(){System.out.println("in c");}
public static void main(String []args){
P b=new C();
b.a();
}}
it will not follow the overriding rule in output (checking object type) and will print "in P".But if you remove static then it will print "in c"
[ October 17, 2008: Message edited by: subhasish nag ]
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Top level classes are the ones which are not inside other classes. That's it...

You can only use public or no modifier with top level classes...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic