Java final abstract class

You can’t get much simpler than using an enum with no instances. public enum MyLib {; public static void myHelperMethod() { } } This class is final, with explicitly no instances and a private constructor. This is detected by the compiler rather than as a runtime error. (unlike throwing an exception)

Instantiating interfaces in Java

No it is not – you are instantiating a Dog, but since a Dog is an Animal, you can declare the variable to be an Animal. If you try to instantiate the interface Animal it would be: Animal baby2 = new Animal(); Try that, and watch the compiler scream in horror 🙂

Best way to declare an interface in C++11

For dynamic (runtime) polymorphism, I would recommend using the Non-Virtual-Interface (NVI) idiom. This pattern keeps the interface non-virtual and public, the destructor virtual and public, and the implementation pure virtual and private class DynamicInterface { public: // non-virtual interface void fun() { do_fun(); } // equivalent to “this->do_fun()” // enable deletion of a Derived* through … Read more

Abstract Method in Ruby

Abstract methods are supposed to be less useful in Ruby because it’s not strongly statically typed. However, this is what I do: class AbstractThing MESS = “SYSTEM ERROR: method missing” def method_one; raise MESS; end def method_two; raise MESS; end end class ConcreteThing < AbstractThing def method_one puts “hi” end end a = ConcreteThing.new a.method_two … Read more

Why does Java not allow multiple inheritance but does allow conforming to multiple interfaces with default implementations

Things are not so simple. If a class implements multiple interfaces that defines default methods with the same signature the compiler will force you to override this method for the class. For example with these two interfaces : public interface Foo { default void doThat() { // … } } public interface Bar { default … Read more

Why can’t you call abstract functions from abstract classes in PHP?

This is a correct implementation; you should use static, not self, in order to use late static bindings: abstract class AbstractFoo{ public static function foo() { throw new RuntimeException(“Unimplemented”); } public static function getFoo(){ return static::foo(); } } class ConcreteFoo extends AbstractFoo{ public static function foo(){ return “bar”; } } echo ConcreteFoo::getFoo(); gives the expected … Read more

Java: static field in abstract class

If you want classes B and C to have separate static variables, you’ll need to declare the variables in those classes. Basically, static members and polymorphism don’t go together. Note that accessing static members through references is a really bad idea in terms of readability – it makes it look like it depends on the … Read more

Can an enum have abstract methods?

Yes, but you may prefer enum which implements an interface, Look here. I think It looks much better. This is example for abstract method: public enum Animal { CAT { public String makeNoise() { return “MEOW!”; } }, DOG { public String makeNoise() { return “WOOF!”; } }; public abstract String makeNoise(); }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)