Can we instantiate an abstract class directly? [duplicate]

You can’t directly instantiate an abstract class, but you can create an anonymous class when there is no concrete class: public class AbstractTest { public static void main(final String… args) { final Printer p = new Printer() { void printSomethingOther() { System.out.println(“other”); } @Override public void print() { super.print(); System.out.println(“world”); printSomethingOther(); // works fine } … Read more

Is Inheritance really needed?

Really really short answer: No. Inheritance is not needed because only byte code is truly needed. But obviously, byte code or assemble is not a practically way to write your program. OOP is not the only paradigm for programming. But, I digress. I went to college for computer science in the early 2000s when inheritance … Read more

Is there a more modern, OO version of “Let’s Build a Compiler”? [closed]

It sounds like you completely missed the point of Crenshaw’s tutorials. LBC isn’t about writing pretty, clean, or efficient code. It’s all about bringing something that’s steeped in formal theory down to a level where the casual coder can easily and rapidly hack out a rudimentary (but working!) compiler. When I read through LBC years … Read more

What’s the function of a static constructor in a non static class?

Do you use it to initialize static fields on your instance of the non-static type? Pretty much, except that static fields (or static members of any kind) aren’t associated with instances; they are associated with the type itself, regardless of whether it is a static class or a non-static class. The documentation lists some properties … Read more

What is the fragile base class problem?

A fragile base class is a common problem with inheritance, which applies to Java and any other language which supports inheritance. In a nutshell, the base class is the class you are inheriting from, and it is often called fragile because changes to this class can have unexpected results in the classes that inherit from … Read more

Java : If A extends B and B extends Object, is that multiple inheritance

My answer is correct? Yes, mostly, and certainly in the context you describe. This is not multiple inheritance: It’s what you said it is, single inheritance with multiple levels. This is multiple inheritance: Inheriting from two or more bases that don’t have any “is a” relationship with each other; that would be inheriting from unrelated … Read more