Skip to content

Instantly share code, notes, and snippets.

@bryanmikaelian
Created June 17, 2011 13:40
Show Gist options
  • Save bryanmikaelian/1031432 to your computer and use it in GitHub Desktop.
Save bryanmikaelian/1031432 to your computer and use it in GitHub Desktop.
OO Programmer test (C#)
using System;
namespace Programmer {
public class Skillz {
public static void Main() {
Console.WriteLine("Round 1. CODE!");
Console.WriteLine("--------------\n");
// Question 1: What is the output?
Person aPerson = new Person("Steve Jobs"); // Hello Steve Jobs.
// Question 2: What is the output?
aPerson.stayUpLate(); // Steve Jobs is not tired and will stay up late.
// Question 3: What is the output?
aPerson.writeCode(); // Does not compile. No method writeCode exists for Person
// Question 4: What is the output?
Doctor aDoctor = new Doctor("Gregory House"); // Hello Gregory House. Hello Dr. Gregory House.
// Question 5: What is the output?
aDoctor.testCode(); // Testing your genetic code yieled nothing
// Question 6: What is the output?
aDoctor.stayUpLate(); // Gregory House is not tired and will stay up late.;
// Question 7: What is the output?
Programmer programmerOne = new Programmer("Hacker Broseph"); // Hello Hacker Broseph.
// Question 8: What is the output?
Console.WriteLine(programmerOne.Name); // Hacker Broseph
// Question 9: What is the output?
Console.WriteLine((Person)programmerOne.Name); // Compile error
// Question 10: What is the output?
programmerOne.stayUpLate(); // Hacker Broseph was bored and decided to stay up late and code through the night.
// Question 11: What is the output?
Person anotherPerson = (Person)programmerOne;
anotherPerson.stayUpLate(); // Hacker Broseph is not tired and will stay up late.
// Question 12: What is the output?
Console.WriteLine(anotherPerson.Name); // Hacker Broseph
// Question 13: What is the output?
Doctor anotherDoctor = (Doctor)programmerOne; // Error.
// Question 14: What is the output?
anotherPerson.testCode(); // My code is tested in production
// Question 15: What is the output?
programmerOne.testCode(); // My code is tested in production
// Question 16: What is the output?
aPerson.testCode(); // I am using this new software I bought!
// Question 17: What is the output?
IProgrammer programmer = new Programmer("Leeterman Skillzor"); // Hello Leeterman Skillzor
// Question 18: What is the output?
programmer.Name; // Error. Name is not a property of the interface type.
// Question 19: What is the output?
Person thirdPerson = (Person)programmer;
thirdPerson.testCode(); // My code is tested in production
// Question 20: What is the output?
programmer.writeCode(); // Code code code code.
}
}
// Begin the fun...
interface IProgrammer {
void writeCode();
void testCode();
void stayUpLate();
}
public class Person {
private string _name;
public string Name {
get { return _name; }
}
public Person(string name) {
this._name = name;
Console.WriteLine(string.Format("Hello {0}.", this._name));
}
public void stayUpLate() {
Console.WriteLine(string.Format("{0} is not tired and will stay up late.", this._name));
}
public virtual void testCode() {
Console.WriteLine("I am using this new software I bought!");
}
}
public class Doctor : Person {
private readonly string suffex = "Dr.";
private string _name;
new public string Name {
get { return _name; }
}
public Doctor(string name) : base(name) {
this._name = string.Format("{0} {1}", this.suffex, name);
Console.WriteLine(string.Format("Hello {0}.", this._name));
}
new public void testCode() {
Console.WriteLine("Testing your genetic code yieled nothing.");
}
}
public class Programmer : Person, IProgrammer {
private string _name;
new public string Name {
get { return _name; }
}
public Programmer(string name) : base(name) {
this._name = name;
}
public void writeCode() {
Console.WriteLine("Code code code code.");
}
public override void testCode() {
Console.WriteLine("My code is tested in production.");
}
new public void stayUpLate() {
Console.WriteLine(string.Format("{0} was bored and decided to stay up late and code through the night.", this._name));
}
}
}
@bryanmikaelian
Copy link
Author

I am trying to think of a way to help our development team get good developers with strong OO fundamentals. This is just something I whipped up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment