M
M
mix-92018-09-30 19:19:40
Java
mix-9, 2018-09-30 19:19:40

What is the best way to write java class inheritance?

Good day.

class Parent {}
....
Parent p = new Parent() {
  public void Hello() {}
}

I understand correctly that a new anonymous class is being created here? If so, does it differ technically (memory, time, etc.) from the usual one?
class Parent {}
class Child extends Parent {
  public void Hello() {}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-09-30
@mix-9

No, it's not different. In both cases, the compiler will save completely identical bytecode to class files. The only difference is that in the first case, the compiler will generate a class name of the form External_class_name$Internal_class_number .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question