aspose file tools*
The moose likes Java in General and the fly likes Confusion 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 » Java » Java in General
Bookmark "Confusion" Watch "Confusion" New topic
Author

Confusion

Aamir Sohail
Greenhorn

Joined: Aug 29, 2010
Posts: 14
hey friends i m new to java , i learn that after implementing interface, we have override all its method bt in below code show1() is not override but it is extending by Mynewclass,, can anybody explain me that concept,, thank you.



[HENRY:added code tags]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30758
    
156

Aamir,
Welcome to JavaRanch!

A class only has to implement all the methods in the interface if it is not "abstract." If it is abstract, the unimplemented methods, act as abstract methods in the class and the subclass has to implement it.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61419
    
  67

Please be sure to take the time to compose descriptive subjects for your posts. You will attract people who will can give you better and faster answers when your posts have good, descriptive subjects. For more information, please click this link ⇒ UseAMeaningfulSubjectLine.

Using a title such as "confusion" isn't going to attract the attention of those who can best help you.

You can change your subject line by clicking the button on your post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sriram Naga
Greenhorn

Joined: Aug 24, 2010
Posts: 8
@Aamir

Also note that you can't instantiate an abstract class. The subclass which extends the abstract class needs to implement the unimplemented methods(declared as abstract in this case).


[My Page] | [JavaRanch FAQ] | SCJP6

"I am not afraid of the storm, as I am learning to sail my ship"
Aamir Sohail
Greenhorn

Joined: Aug 29, 2010
Posts: 14
thank you friends,,,, and sir i will take care of it ,,,, thank you
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Sriram Gsn wrote:you can't instantiate an abstract class.

who said..we can even instantiate interface.


SCJP6.0,My blog Ranchers from Delhi
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

No you can't. You can instantiate anonymous inner classes that extend an abstract class or implement an interface, but you can't instantiate an abstract class or interface itself.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Aamir Sohail
Greenhorn

Joined: Aug 29, 2010
Posts: 14
actually instantiating, according to shanky, we can create reference of that abstract class.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
You can always create a reference to an abstract class (or an interface). You simply have to point that at an instantiation of a concrete subclass or implementation.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

in case of the inner class we can instantiate the interface as well as abstract class provided we have to give the implementation of the methods to.

lets see below..


Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4421
    
    8

Shanky Sohar wrote:in case of the inner class we can instantiate the interface as well as abstract class provided we have to give the implementation of the methods to.

No, Rob's right. That's not instantiating the interface. That's creating, and then instantiating, an anonymous inner class that implements the interface.

Try adding this line:
It won't output "Testing".

Terminology matters
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Oh there was little confusin from my side in this..
So i have it now
here we are creating a annonymouse class which is having the implemention of the interface

And anonymous class start just after when we have done this
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confusion