Final with Inheritance

We have two uses

  1. To Prevent Overriding
class A {
 final void meth() {
 System.out.println("This is a final method.");
 }
}
class B extends A {
 void meth() { // ERROR! Can't override.
 System.out.println("Illegal!");
 }
}
  1. To Prevent Inheritance
final class A {
 //...
}
// The following class is illegal.
class B extends A { // ERROR! Can't subclass A
 //...
}

Object Class

It is a special class where all classes derived from this only means that a reference variable of type Object can refer to an object of any other class.

return type for getClass( ).

object is output using println( ).

toString( ) method returns a string that contains a description of the object.

equals( ) method compares two objects

results matching ""

    No results matching ""