Using Final to Prevent Inheritance Assignment Help

Assignment Help: >> Inheritance in Java - Using Final to Prevent Inheritance

Using final to Prevent Inheritance

Many times you will need to avoid a class from being inherited. To do this, process the class declaration along with final. Declaring a class a final implicitly declares all of its methods a final, too. As you may expect, it is illegal to declare a class as both abstract and final because an abstract class is incomplete through itself and relies upon its subclasses to gives complete implementations.

Here is an instance of a final class:

final class A {

// ...

}

// The following class is illegal.

class B extends A { // ERROR! Can't subclass A

// ...

}

As comments imply, this is illegal for B to inherit A because A is declared as final.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd