4

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.

sachin garg
  • 1,316
  • 15
  • 27
AndroidOptimist
  • 1,419
  • 3
  • 23
  • 38

3 Answers3

1

'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.

sachin garg
  • 1,316
  • 15
  • 27
0

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.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
0

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()
            {

            }
 }
}
Amritha
  • 778
  • 9
  • 12