Java Final Exam Review Sheet

Help with Final Exam Review

Page 1 of 1

2 Replies - 12905 Views - Last Post: 09 December 2007 - 03:05 PM Rate Topic: -----

#1 m_milam  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 28
  • Joined: 15-September 07

Java Final Exam Review Sheet

Post icon  Posted 09 December 2007 - 09:29 AM

I am nearing the end of my first Java class and I am studying for my final. I was given a review quiz to study off of and I feel confident I know this stuff but would like a second opinion. If I am wrong if you could please point out why I am wrong so I can better understand this going into my final. The final is on Monday and thanks in advance for the help.


1 . Suppose s1 and s2 are two strings. Which of the following statements or expressions are incorrect? 
a. String s3 = s1 - s2; 
b. int i = s1.compareTo(s2); 
c. char c = s1[0]; char c = s1.charAt(s1.length() - 1); 
e. a and c. 

Your choice is ___B____ 

2. How can you initialize a string with "123"? 
a. String[] string = {'1', '2', '3'}; 
b. String string = {'1', '2', '3'}; 
c. String s = "123"; 
d. String s = new String("123"); 
e. c and d are both fine, but c is better. 

Your choice is ___E_____ 

3. A subclass inherits _____________ from its superclasses. 
a.private data 
b.protected data 
c.public data 
d.a and c 
e.b and c 

Your choice is _____E ___ 

4. When you implement a method that is defined in a superclass, you __________ the original method. 
a. overload 
b. override 
c. copy 
d. call 

Your choice is ___B_____

5.   
Analyze the following code.

class Test { 
  public static void main(String[] args) {
	Inner inner = new Inner();
	System.out.println(inner.k);
  }

  private class Inner {
	protected int k;
  }
}

a.	The program has a syntax error because the Inner class does not have a constructor and you cannot create an object from it.
b.	The program has a syntax error because the Inner class is private and it cannot be accessed in the main method .
c.	The program has a syntax error because k is protected in the Inner class and it cannot be accessed in the main method.
d.	The program has a syntax error because the Inner class is not static and it cannot be used to create an object in the main method.
				 

 
		  Your choice is ____D____

 

6.   . Which of the following possible modifications will fix the errors in this code?

public class Test { 
  private double code;

  public double getCode() {
	return code;
  }

  protected abstract void setCode(double code);
}

a.	Remove abstract in the setCode method declaration.
b.	Change protected to public.
c.	Add abstract in the class declaration.
d.	b and c. 

			Your choice is ___D_____




Thanks again for any insight. This forum has made my learning experience a lot easier.

Is This A Good Question/Topic? 0
  • +

Replies To: Java Final Exam Review Sheet

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: Java Final Exam Review Sheet

Posted 09 December 2007 - 11:01 AM

Well I can tell you immediately that number 1 is wrong. I think you just misread the question. They ask for the ones that are INCORRECT. The answer should be E. A is incorrect because you can't simply subtract strings, the string class doesn't have implementation for the minus operator. C is incorrect because you can't treat the string as an array in this situation. String is a class.

Then on number 6 all you should really need to do is add abstract. No need to change protected to public. It will compile as protected and simply states that it needs to be overridden in a child class and that it is only available to child classes. I have seen protected abstract functions used before.

So I would say the answer there is C.
Was This Post Helpful? 0
  • +
  • -

#3 m_milam  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 28
  • Joined: 15-September 07

Re: Java Final Exam Review Sheet

Posted 09 December 2007 - 03:05 PM

View PostMartyr2, on 9 Dec, 2007 - 11:01 AM, said:

Well I can tell you immediately that number 1 is wrong. I think you just misread the question. They ask for the ones that are INCORRECT. The answer should be E. A is incorrect because you can't simply subtract strings, the string class doesn't have implementation for the minus operator. C is incorrect because you can't treat the string as an array in this situation. String is a class.

Then on number 6 all you should really need to do is add abstract. No need to change protected to public. It will compile as protected and simply states that it needs to be overridden in a child class and that it is only available to child classes. I have seen protected abstract functions used before.

So I would say the answer there is C.



Thanks for point that out. I did misread number 1. I feel like I have a good grasp on the concepts and should do well on my final especially if this review is any indication of what the test will be like.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1