CSci 2101: Review for Final Exam

Theory of data structures

True or false:

Problems:

Types and subtyping

Is the following program syntactically correct? If not, comment out the lines that are causing compiler errors. What will be the result of running the program after that? Show all the output and all runtime exceptions (if any).



public interface A {
	public void m();
}

public class B implements A {

	@Override
	public void m() {
		System.out.println("This is m in B");
	}

	public void mmm() {
		System.out.println("This is mmm in B");
	}
}


public class C extends B {
	
	public void m() {
		System.out.println("This is m in C");
	}
	
	public void mmm() {
		System.out.println("This is mmm in C");
	}
}


public class TestSubtypes {
	public static void main(String [] args) {
		A a1 = new B();
		A a2 = new C();
		
		a1.m();
		a2.m();
		
		a1.mmm();
		((B) a1).mmm();
		((B) a2).mmm();
		((C) a2).mmm();
		((C) a1).mmm();
	}

}

Programming exercise

Write a method of binary tree that returns true if the tree is a binary serach tree and false otherwise.


CSci 2101 course web site.