Results 1 to 6 of 6
Thread: Java Review
- 12-07-2007, 06:57 PM #1
Member
- Join Date
- Oct 2007
- Posts
- 11
- Rep Power
- 0
Java Review
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.
This is the first part of the reveiw sheet and is the only part I have filled in at this point. Thanks again for any insight. This forum has made my learning experience a lot easier.Java Code: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 ___ E____ 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_____
- 12-07-2007, 07:37 PM #2
I'm pretty sure that c is valid in #1. I would write a test program to make sure.
- 12-07-2007, 07:39 PM #3
Member
- Join Date
- Oct 2007
- Posts
- 11
- Rep Power
- 0
I figured C was valid but wouldn't a be valid as well? If not can you briefly explain why it wouldn't? I am try to get a complete understanding of the concepts.
- 12-07-2007, 08:18 PM #4
1 - e
2 - e
3 - e
4 - b
The "+" operator works for concatenation of/in strings. You cannot apply the "-" operator to strings.Java Code:String s3 = s1 - s2;
s1[0] is array notation and does not work for a String. For this to work the variable "s1" would have to be of type char[].Java Code:char c = s1[0];
- 12-07-2007, 09:26 PM #5
Member
- Join Date
- Oct 2007
- Posts
- 11
- Rep Power
- 0
I am a littile confused. At first it appears that you are saying I have answered correct (wouldn't that be great) but when I read the comment below the code snippets it looks like for problem 1 neither (a) or (c) would work so (e) would be incorrect. I maybe totally misreading what you posted. Thanks again.
- 12-08-2007, 01:28 AM #6
Similar Threads
-
Java Review Question
By toad in forum New To JavaReplies: 1Last Post: 10-29-2007, 06:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks