first commit
This commit is contained in:
73
CS1322/t2/t2 pract.txt
Normal file
73
CS1322/t2/t2 pract.txt
Normal file
@@ -0,0 +1,73 @@
|
||||
Review questions for test 2:
|
||||
|
||||
1) Define the following words:
|
||||
|
||||
- polymorphism
|
||||
- inheritance
|
||||
- dynamic binding
|
||||
- scope
|
||||
- variable shadowing
|
||||
- this()
|
||||
- super()
|
||||
- constructor chaining
|
||||
- toString
|
||||
- .equals
|
||||
- reference
|
||||
- object
|
||||
- class
|
||||
|
||||
|
||||
2) Write the method
|
||||
public String reverse(String s)
|
||||
which returns the String backwards.
|
||||
You may assume that s is not null.
|
||||
You must use recursion ONLY.
|
||||
|
||||
{
|
||||
|
||||
|
||||
|
||||
3) Write the method
|
||||
public boolean isPalindrome(String s)
|
||||
which returns true if and only if s is a palindrome, false otherwise.
|
||||
You may assume that s is not null.
|
||||
You must use recursion ONLY.
|
||||
Remember that a palindrome is a String that is the same forwards as
|
||||
backwards.
|
||||
|
||||
4) Write the method
|
||||
public void printTwoSquares(int a, int b)
|
||||
which prints out two squares of # marks, one of size a, one
|
||||
of size b, that are next to each other.
|
||||
For example,
|
||||
|
||||
printTwoSquares(3,5)
|
||||
would print
|
||||
|
||||
### #####
|
||||
### #####
|
||||
### #####
|
||||
#####
|
||||
#####
|
||||
|
||||
5) Given the following class:
|
||||
public class Clock
|
||||
{
|
||||
int time;
|
||||
public Clock(int time)
|
||||
{
|
||||
this.time=time;
|
||||
}
|
||||
}
|
||||
Write the class AlarmClock, which
|
||||
o is a subclass of Clock
|
||||
o has an int for alarmTime
|
||||
o has a constructor which takes both the alarmTime and the time,
|
||||
uses the super constructor to initalize time, and then intializes
|
||||
alarmTime
|
||||
o has a default constructor which constructor chains with 0 for
|
||||
the time and 0 for the alarm time
|
||||
o has an accessor and modifier for alarmTime
|
||||
|
||||
6) Do you understand all of the concepts and how to code them from p2 phase I?
|
||||
Just memorizing the code is *NOT* the way to go.
|
||||
Reference in New Issue
Block a user