带有示例的黑白私人班级与密封班级的区别

编程入门 行业动态 更新时间:2024-10-24 14:22:28
本文介绍了带有示例的黑白私人班级与密封班级的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

谁能告诉我有关示例的区别黑白私有类与密封类.

Hi, Can anybody tell me about the Difference b/w private class vs sealed class with example.

推荐答案

私有 :私有limits the visiblity to a scope.在一个类中声明一个私有类意味着从该类的外部看到"sub-class" can''t. 方法和属性也是如此-它们可以在类中看到,但对任何使用者或继承者都不可见. Private关键字用于声明类. 密封的:如果将一个类声明为密封的,则表示you cannot inherit from the class.当某个类在库,该类或该类的操作的内部是内部的,而您不希望该类被覆盖(因为它可能影响功能)时,可以使用密封类. Sealed 关键字用于声明类 请参考: 密封类和私有类之间的区别 [ ^ ] 密封阶级与私人阶级之间的区别 [ ^ ] Private: Private limits the visiblity to a scope. Declaring a private class within a class means that "sub-class" can''t be seen from outside of the class. This is also true for methods and properties - they can be seen within the class, but not to any consumers or inheritors. Private keyword is used for declaring class. Sealed: If a class is declared as sealed, that means that you cannot inherit from the class. Sealed class can be used when a class is internal to the operation of the library, class or whwn you donot want that class to be overridden because it may affect the functionality. Sealed keyword is used for declaring class Pleae refer: diff between sealed class and private class[^] difference between Sealed Class and Private Class[^]

我给您链接,希望对您有所帮助 C#调整–为什么在类? [ ^ ] 公共抽象密封类MyFundooClass {} [ ^ ] C#.NET中的面向对象编程-第4部分 [ ^ ] 私人的:只有班级成员可以访问.但可以在任何类中继承. 如果在C#中将类定义为密封",在VB.NET中将类定义为不可继承",则不能 进一步继承该类. 现在,我将通过简单的示例来更清楚 i give you link i hope it will help you C# Tweaks – Why to use the sealed keyword on classes?[^] public abstract sealed class MyFundooClass {}[^] Object-Oriented Programming in C# .NET - Part 4[^] Private : Only members of class have access. but it can be inherit in any class. If you define a class as "Sealed" in C# and "NotInheritable" in VB.NET you can not inherit the class any further. now i will more clear with simple example private class abc // private class it { void abc() { } public void show() { string abc = ""; } } sealed class efg // Sealed class it { void efg() { } public void showefg() { string abc = ""; } } public class cde : abc // in this class we inherit private class abc { void cde() { show(); // private class method show } } public class ghi : efg // we cannot inherit sealed class and it method { void ghi() { // not showing sealed class method showefg() even it is public } } protected void Page_Load(object sender, EventArgs e) { cde c = new cde();// calling private class method by inheritance c.show(); }

私有类只能由其定义并包含在内部的类访问-外部类完全无法访问. Sealed类可以由任何类访问,但不能派生自该类. A Private class can only be accessed by the class it is defined and contain within - it is completely inaccessible to outside classes. A Sealed class can be accessed by any class, but can not be derived from. public class A { private class B { } B b = new B(); } public class C { A.B b = new A.B(); // ERROR }

public sealed class A { } public class B : A //ERROR { }

更多推荐

带有示例的黑白私人班级与密封班级的区别

本文发布于:2023-10-31 05:56:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545210.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:班级   示例   黑白   私人   区别

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!