There is no similar construction in Java.
(Do not confuse newwith the opposite @Override. This is not so.)
Consider this C # code:
class A {
virtual public int x() { return 1; }
virtual public int y() { return 1; }
}
class B : A {
new public int x() { return 2; }
override public int y() { return 2; }
}
void Main()
{
A aa = new A();
A ba = new B();
B bb = new B();
aa.x().Dump();
ba.x().Dump();
bb.x().Dump();
"---".Dump();
aa.y().Dump();
ba.y().Dump();
bb.y().Dump();
}
When launched in LINQPad, this generates:
1
1
2
---
1
2
2
, , , new override. new , . ... .
.
user166390