Created
November 4, 2011 20:59
-
-
Save aeris/1340477 to your computer and use it in GitHub Desktop.
Héritage et polymorphisme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
private static class A { | |
protected void foo() { | |
System.out.println("A"); | |
} | |
} | |
private static class B extends A { | |
@Override | |
protected void foo() { | |
System.out.println("B"); | |
} | |
} | |
public static void main(final String[] args) { | |
final A a = new A(); | |
a.foo(); | |
final B b = new B(); | |
b.foo(); | |
final A c = b; | |
c.foo(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Foo { | |
public class Bar { | |
private class A { | |
public void Foo() { | |
Console.Out.WriteLine("A"); | |
} | |
} | |
private class B : A { | |
public void Foo() { | |
Console.Out.WriteLine("B"); | |
} | |
} | |
public static void Main(string[] args) { | |
A a = new A(); | |
a.Foo(); | |
B b = new B(); | |
b.Foo(); | |
A c = b; | |
c.Foo(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Foo { | |
public class Bar { | |
private class A { | |
public void Foo() { | |
Console.Out.WriteLine("A"); | |
} | |
} | |
private class B : A { | |
public new void Foo() { | |
Console.Out.WriteLine("B"); | |
} | |
} | |
public static void Main(string[] args) { | |
A a = new A(); | |
a.Foo(); | |
B b = new B(); | |
b.Foo(); | |
A c = b; | |
c.Foo(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Foo { | |
public class Bar { | |
private class A { | |
public virtual void Foo() { | |
Console.Out.WriteLine("A"); | |
} | |
} | |
private class B : A { | |
public override void Foo() { | |
Console.Out.WriteLine("B"); | |
} | |
} | |
public static void Main(string[] args) { | |
A a = new A(); | |
a.Foo(); | |
B b = new B(); | |
b.Foo(); | |
A c = b; | |
c.Foo(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Foo | |
{ | |
public class Bar { | |
private class A { | |
public void Foo() { | |
Console.Out.WriteLine("A"); | |
} | |
} | |
private class B : A { | |
public override void Foo() { | |
Console.Out.WriteLine("B"); | |
} | |
} | |
public static void Main(string[] args) { | |
A a = new A(); | |
a.Foo(); | |
B b = new B(); | |
b.Foo(); | |
A c = b; | |
c.Foo(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment