oop
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
How to get property values of classes that implement an interface in the Locals window?
I could be wrong, but I think this may be something to do with the way classes are instantiated in VBA. For example: Dim oClass1 as Class1 Set oClass1 = new Class1 Is different than Dim oClass1 as New Class1 In the second case I believe the constructor doesn’t get called until the property is … 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
How and when to use an abstract class
You’d use an abstract class or interface here in order to make a common base class/interface that provides the void draw() method, e.g. abstract class Shape() { void draw(); } class Circle extends Shape { void draw() { … } } … Shape s = new Circle(); s.draw(); I’d generally use an interface. However you … 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