aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overridding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overridding" Watch "Overridding" New topic
Author

Overridding

Raj Gahalot
Greenhorn

Joined: Aug 07, 2008
Posts: 7
1. Can we override static methods?

2. What is top level class and what are the modifiers we can use in top level class?


Raj<br />Preparing for SCJP1.5
Pawan Arora
Ranch Hand

Joined: Sep 14, 2008
Posts: 105
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

Joined: Aug 03, 2008
Posts: 9305
    
  17

Well there is a huge confusion with everybody about static method overriding.

well actually static methods are hidden and not overridden.

see this link


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
sweety sinha
Ranch Hand

Joined: Jul 07, 2008
Posts: 76

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

Joined: Apr 25, 2008
Posts: 101
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 ]

Thanks,<br />Subhasish
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overridding