Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
How can anonymous class extend any other class?
Hemal Mehta
Ranch Hand
Posts: 101
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How can anonymous class extend any other class? Can it be done explicitly?
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
I like...
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The following code shows how to go about making an anonymous class extend any other class.
//superclass A class A { public void doSomething() { System.out.println("A"); } } public class Test { public static void main(String[] args) { //declaration of the anonymous extension of superclass A A a = new A() { // overridden version of doSomething public void doSomething() { System.out.println("anonymous extension of A"); //invoke superclass' doSomething method super.doSomething(); } }; //do some stuff a.doSomething(); } }
The output is
anonymous extension of A
A
[ February 07, 2003: Message edited by: Valentin Crettaz ]
My Linked In
Igor Zeta
Ranch Hand
Posts: 40
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You can't do it explicitly using the extends keyword
ciao<br />Igor Zeta<br />SCJP1.4
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
I like...
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It is strictly prohibited to use the "extends" and "implements" keywords in an anonymous class declaration.
[ February 07, 2003: Message edited by: Valentin Crettaz ]
My Linked In
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Ever a case when a class cannot extend or inherit anything
Anonymous class
Extending a class
anonymous class
anonymous classes
More...