Why is this valid boolean b = new A() instanceof A; if A is an abstract class? [closed] The 2019 Stack Overflow Developer Survey Results Are InJava abstract class namingWhy should I declare a class as an abstract class?Why should a class be anything other than “abstract” or “final/sealed”?Java's Boolean class - why not an enum?Why 'List<E>' is an 'interface' but not 'abstract class'?Is there an alternative to instanceof when filtering a Java stream by class?What is the rule for nested loop code?Why override a static method of an abstract base class?When and why would you put a new method into an interface instead of an abstract base class?Avoiding instanceof vs abstract God Class. Do I have an alternative?

Why isn't airport relocation done gradually?

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

Can someone be penalized for an "unlawful" act if no penalty is specified?

Did 3000BC Egyptians use meteoric iron weapons?

Delete all lines which don't have n characters before delimiter

Can you compress metal and what would be the consequences?

Are there incongruent pythagorean triangles with the same perimeter and same area?

Building a conditional check constraint

How to obtain Confidence Intervals for a LASSO regression?

Did Section 31 appear in Star Trek: The Next Generation?

How to deal with fear of taking dependencies

How do I change the ":" symbol in the minibuffer?

If I score a critical hit on an 18 or higher, what are my chances of getting a critical hit if I roll 3d20?

Are children permitted to help build the Beis Hamikdash?

How does one change the certificate and key for a web service with Strict-Transport-Security established

Do these rules for Critical Successes and Critical Failures seem Fair?

"as much details as you can remember"

Is this app Icon Browser Safe/Legit?

What is the closest word meaning "respect for time / mindful"

Why can Shazam fly?

Aging parents with no investments

Protecting Dualbooting Windows from dangerous code (like rm -rf)

Can we generate random numbers using irrational numbers like π and e?

How to manage monthly salary



Why is this valid boolean b = new A() instanceof A; if A is an abstract class? [closed]



The 2019 Stack Overflow Developer Survey Results Are InJava abstract class namingWhy should I declare a class as an abstract class?Why should a class be anything other than “abstract” or “final/sealed”?Java's Boolean class - why not an enum?Why 'List<E>' is an 'interface' but not 'abstract class'?Is there an alternative to instanceof when filtering a Java stream by class?What is the rule for nested loop code?Why override a static method of an abstract base class?When and why would you put a new method into an interface instead of an abstract base class?Avoiding instanceof vs abstract God Class. Do I have an alternative?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have trouble understanding why this boolean b = new A() instanceof A; is a valid statement and not boolean b = new A() instanceof A; and why the former is true knowing that A is an abstract class.










share|improve this question







New contributor




Dr.Stone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











closed as off-topic by gnat, Bart van Ingen Schenau, David Arno, amon, Deduplicator Apr 5 at 10:06


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions asking for assistance in explaining, writing or debugging code are off-topic here. These can be asked on Stack Overflow if they include the desired behavior, a specific problem or error, and the shortest code necessary to reproduce it in the question (see Minimal, Complete, and Verifiable Example)." – gnat, amon, Deduplicator
If this question can be reworded to fit the rules in the help center, please edit the question.






















    1















    I have trouble understanding why this boolean b = new A() instanceof A; is a valid statement and not boolean b = new A() instanceof A; and why the former is true knowing that A is an abstract class.










    share|improve this question







    New contributor




    Dr.Stone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.











    closed as off-topic by gnat, Bart van Ingen Schenau, David Arno, amon, Deduplicator Apr 5 at 10:06


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Questions asking for assistance in explaining, writing or debugging code are off-topic here. These can be asked on Stack Overflow if they include the desired behavior, a specific problem or error, and the shortest code necessary to reproduce it in the question (see Minimal, Complete, and Verifiable Example)." – gnat, amon, Deduplicator
    If this question can be reworded to fit the rules in the help center, please edit the question.


















      1












      1








      1








      I have trouble understanding why this boolean b = new A() instanceof A; is a valid statement and not boolean b = new A() instanceof A; and why the former is true knowing that A is an abstract class.










      share|improve this question







      New contributor




      Dr.Stone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I have trouble understanding why this boolean b = new A() instanceof A; is a valid statement and not boolean b = new A() instanceof A; and why the former is true knowing that A is an abstract class.







      java object-oriented






      share|improve this question







      New contributor




      Dr.Stone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Dr.Stone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Dr.Stone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Apr 5 at 1:19









      Dr.StoneDr.Stone

      192




      192




      New contributor




      Dr.Stone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Dr.Stone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Dr.Stone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      closed as off-topic by gnat, Bart van Ingen Schenau, David Arno, amon, Deduplicator Apr 5 at 10:06


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Questions asking for assistance in explaining, writing or debugging code are off-topic here. These can be asked on Stack Overflow if they include the desired behavior, a specific problem or error, and the shortest code necessary to reproduce it in the question (see Minimal, Complete, and Verifiable Example)." – gnat, amon, Deduplicator
      If this question can be reworded to fit the rules in the help center, please edit the question.







      closed as off-topic by gnat, Bart van Ingen Schenau, David Arno, amon, Deduplicator Apr 5 at 10:06


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Questions asking for assistance in explaining, writing or debugging code are off-topic here. These can be asked on Stack Overflow if they include the desired behavior, a specific problem or error, and the shortest code necessary to reproduce it in the question (see Minimal, Complete, and Verifiable Example)." – gnat, amon, Deduplicator
      If this question can be reworded to fit the rules in the help center, please edit the question.




















          1 Answer
          1






          active

          oldest

          votes


















          16














          The instanceof A has nothing to do with whether the statement is valid or not, so your question is simpler if you leave it off from both statements:



          A a = new A() ;
          A a = new A();


          The second statement isn't valid because A is abstract and you can't call new on any abstract class. If you could instantiate it, it would be an instance of A, but you can't.



          The first statement is valid because it creates an anonymous class that extends A. This anonymous class isn't abstract (assuming A doesn't define any abstract methods), and so it can be instantiated. It's an instance of A because all subclasses are instances of their parent classes, abstract or not. It's basically a shortcut for saying:



          public class AnonymousNameIDontCareAbout extends A 
          A a = new AnonymousNameIDontCareAbout();





          share|improve this answer





























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            16














            The instanceof A has nothing to do with whether the statement is valid or not, so your question is simpler if you leave it off from both statements:



            A a = new A() ;
            A a = new A();


            The second statement isn't valid because A is abstract and you can't call new on any abstract class. If you could instantiate it, it would be an instance of A, but you can't.



            The first statement is valid because it creates an anonymous class that extends A. This anonymous class isn't abstract (assuming A doesn't define any abstract methods), and so it can be instantiated. It's an instance of A because all subclasses are instances of their parent classes, abstract or not. It's basically a shortcut for saying:



            public class AnonymousNameIDontCareAbout extends A 
            A a = new AnonymousNameIDontCareAbout();





            share|improve this answer



























              16














              The instanceof A has nothing to do with whether the statement is valid or not, so your question is simpler if you leave it off from both statements:



              A a = new A() ;
              A a = new A();


              The second statement isn't valid because A is abstract and you can't call new on any abstract class. If you could instantiate it, it would be an instance of A, but you can't.



              The first statement is valid because it creates an anonymous class that extends A. This anonymous class isn't abstract (assuming A doesn't define any abstract methods), and so it can be instantiated. It's an instance of A because all subclasses are instances of their parent classes, abstract or not. It's basically a shortcut for saying:



              public class AnonymousNameIDontCareAbout extends A 
              A a = new AnonymousNameIDontCareAbout();





              share|improve this answer

























                16












                16








                16







                The instanceof A has nothing to do with whether the statement is valid or not, so your question is simpler if you leave it off from both statements:



                A a = new A() ;
                A a = new A();


                The second statement isn't valid because A is abstract and you can't call new on any abstract class. If you could instantiate it, it would be an instance of A, but you can't.



                The first statement is valid because it creates an anonymous class that extends A. This anonymous class isn't abstract (assuming A doesn't define any abstract methods), and so it can be instantiated. It's an instance of A because all subclasses are instances of their parent classes, abstract or not. It's basically a shortcut for saying:



                public class AnonymousNameIDontCareAbout extends A 
                A a = new AnonymousNameIDontCareAbout();





                share|improve this answer













                The instanceof A has nothing to do with whether the statement is valid or not, so your question is simpler if you leave it off from both statements:



                A a = new A() ;
                A a = new A();


                The second statement isn't valid because A is abstract and you can't call new on any abstract class. If you could instantiate it, it would be an instance of A, but you can't.



                The first statement is valid because it creates an anonymous class that extends A. This anonymous class isn't abstract (assuming A doesn't define any abstract methods), and so it can be instantiated. It's an instance of A because all subclasses are instances of their parent classes, abstract or not. It's basically a shortcut for saying:



                public class AnonymousNameIDontCareAbout extends A 
                A a = new AnonymousNameIDontCareAbout();






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 5 at 3:36









                Karl BielefeldtKarl Bielefeldt

                121k32217415




                121k32217415













                    Popular posts from this blog

                    Magento 1.9 observer on only new product added ( no updated product )Admin Create New Order ObserverObserver checkout_cart_product_add_after get product quantity in cartHow can I differentiate between product creation and saving existing products?How to get the original price Product SaveBeforeMagento Observer for Admin Sales order Address updateHow do i get quantity in a product_save_after event observer magento2?Using observer event to get updated customer infoSave product observer - detect availabilityEvent not triggered when new product added in admin : Magento 2magento 1.9 observer on quantity product change

                    Button value to be changed back to original value on timeout (form double submit)Prevent double submission of forms in jQueryJavaScript post request like a form submitChange the selected value of a drop-down list with jQueryTwo submit buttons in one formPrevent users from submitting a form by hitting EnterHow to prevent buttons from submitting formsjQuery disable/enable submit buttonjQuery AJAX submit formHTML button to NOT submit formCan I make a <button> not submit a form?Cannot display HTML string

                    Does an object always see its latest internal state irrespective of thread? The 2019 Stack Overflow Developer Survey Results Are InDoes a finally block always get executed in Java?Java: serial thread confinement questionJava difference between fixed threadpool and scheduled threadpoolJackrabbit and concurrent modificationHow to stop a Runnable scheduled for repeated execution after a certain number of executionsMultiple threads accessing inner classHow can a loop be completed by two thread? say loop from count=1 to count=4 by ist thread and count =5 to 8 by 2nd thread?If I keep a reference to a Runnable, when does the Thread it ran on get released?How to stop a schedule ScheduledExecutorServiceHow to implement a singleThreadedScheduledExcecutor in wildfly