sealed method in android

367 views Asked by At

I Am a newbie and I am reding about sealed keyword and referred sealed object. I googled but could not find a simple example of using sealed method in android.I tried something like

class A
{
//declarations

}

class B extends A
{

//here i would like to use my sealed override keyword

}

Can anyone tell me how to use this sealed method. Thanks in advance.

3

There are 3 answers

1
Lalit Poptani On

Here is a nice sample example for Securing Java Objects for Plain Text Transport also reading the IBM docs also gives you a better idea.

0
Amritha On

Sealed class is used to define the inheritance level of a class. A class, which restricts inheritance for security reason is declared, sealed class.Sealed class is the last class in the hierarchy. Sealed class can be a derived class but can't be a base class.A sealed class cannot also be an abstract class. Because abstract class.

class A
{

public class B
{

 public void display()
     {
      }

    }


public class c extends B
 {

 public override sealed void Display()
            {

            }
 }
}
0
sachin garg On

'final' is the keyword in Java to achieve sealed behavior. I assume you are coming from C# background. If it is so, please note that in java all the methods are virtual by default and adding final keyword right before method name will prevent it from being overridden.