SampleMidTerm Exam and Review Questions Ira Pohl
Be familiar with Java By Dissection chapters 2-7
and work associated with homework problems 1-3.
Problem 1
Define and a give an example of the following concepts -use Java . No more than
two lines
Concept
overloading
signature
value type
default constructor
container
Problem 2
What gets printed?
public class S {
public S() { i = 2; System.out.println(
"this.i " + i ); }
public void reset(int i) { this.i = i;
}
public void print()
{
for (int k = 0; k <= i; ++k)
System.out.print( data[k] + ", ") ;
System.out.println() ;
}
private static int[] data = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10} ;
private int i;
public static void main(String[] args)
{
S s =new S(), t = new S();
s.print();
t.reset(3);
t.print();
}
}
Problem 3
Answer true or false.
static member functions cannot use the this references
a constructor can be overloaded.
the operator == can be overloaded in Java.
the ternary operator ?: is not allowed in Java.
a compiler never provides a default constructor.
Problem 4
Define Minimum Spanning
Tree:________________________________________
Why is the standard algorithm considered a greedy like method?
Draw a simple undirected complete graph of 5 nodes with integer edge weights
between 1 and 5.
Compute and draw its MST.
OTHER REVIEW:
End of chapter 2-7 short answer review questions