Is the following code snippet show valid inheritance?

class A {
int v;
final String sayHello() {
return "Hello";
}
}
class B extends A {
public int sayHello(int a) {
return 3 + a;
}
}

Recommended Answers

All 3 Replies

It is valid code.
Class B will inherit v and String sayHello(), but nothing in the code makes use of that.

It is valid code.
Class B will inherit v and String sayHello(), but nothing in the code makes use of that.

But String sayHello() is declared final which can not be overloaded...

Yes, but B doesn't try to do anything with that method.
sayHello(int a) is a different method signature from sayHello(); they are two completely different methods.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.