• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

final class

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
this concept i took from devaka's examlab.
why can't final class be applied to instanceof test with the interface which it does not implement?

for eg:

class A{}
class B extends A implements inter{}
final class C{}

class Testex
{
public static void main(String args[])
{
boolean b=new A() instanceof inter;
boolean b1=new B() instanceof inter;
boolean b2=new C() instanceof inter; // compiler error ie. inconvertible type
System.out.println(b+ "," +b1+ "," + b2);
}
}

could someone explain this?

Thanks
Preetha
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simple Arun.
Now your C class is final

final class C{}

So you cannot do

class D extends C implements inter{}

Why? As final class cannot be subclassed.
So It will never be possible to do

C c=new D();

So it is not possible to make subclass of C means now no possibility to make a reference of C will point to an object that implements inter interface. Compiler can detect these things. So it will not allow final class reference to be checked as instanceof any interface that final class is not implementing.
[ December 16, 2008: Message edited by: punit.singh ]
 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect answer, Punit. I am removing my erroneous answer.
[ December 16, 2008: Message edited by: Ruben Soto ]
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic