Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save ufcpp/44c3439146acf073ab38 to your computer and use it in GitHub Desktop.

Select an option

Save ufcpp/44c3439146acf073ab38 to your computer and use it in GitHub Desktop.
Complete type hierarchy
abstract class Message
{
// コンストラクターを private に
private Message() { }
// inner クラスであれば private なコンストラクターにアクセスできる
// なので、以下の A, B, C はコンパイルできる
public sealed class A : Message { }
public sealed class B : Message { }
public sealed class C : Message { }
}
// private なコンストラクターのせいで外からは継承できない
public class D : Message { } // なので、ここでコンパイル エラー
// しかも、A, B, C ともに sealed なので、そいつらを継承することもできない
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment