• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusion

 
Aamir Sohail
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sriram Naga
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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).
 
Aamir Sohail
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you friends,,,, and sir i will take care of it ,,,, thank you
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sriram Gsn wrote:you can't instantiate an abstract class.

who said..we can even instantiate interface.
 
Rob Spoor
Sheriff
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Aamir Sohail
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually instantiating, according to shanky, we can create reference of that abstract class.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50284
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic