Results 1 to 6 of 6

Thread: Java Review

  1. #1
    toad is offline Member
    Join Date
    Oct 2007
    Posts
    11
    Rep Power
    0

    Default 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.

    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_____
    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.

  2. #2
    ShoeNinja's Avatar
    ShoeNinja is offline Senior Member
    Join Date
    Oct 2007
    Posts
    124
    Rep Power
    0

    Default

    I'm pretty sure that c is valid in #1. I would write a test program to make sure.

  3. #3
    toad is offline Member
    Join Date
    Oct 2007
    Posts
    11
    Rep Power
    0

    Default

    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.

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    10

    Default

    1 - e
    2 - e
    3 - e
    4 - b
    Java Code:
    String s3 = s1 - s2;
    The "+" operator works for concatenation of/in strings. You cannot apply the "-" operator to strings.
    Java Code:
    char c = s1[0];
    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[].

  5. #5
    toad is offline Member
    Join Date
    Oct 2007
    Posts
    11
    Rep Power
    0

    Default

    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.

    Quote Originally Posted by hardwired View Post
    1 - e
    2 - e
    3 - e
    4 - b
    Java Code:
    String s3 = s1 - s2;
    The "+" operator works for concatenation of/in strings. You cannot apply the "-" operator to strings.
    Java Code:
    char c = s1[0];
    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[].

  6. #6
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    10

    Default

    Suppose s1 and s2 are two strings. Which of the following statements or expressions are incorrect?
    Which statements are incorrect? Both a and c are incorrect.
    Statement b is correct because String implements the Comparable interface.

Similar Threads

  1. Java Review Question
    By toad in forum New To Java
    Replies: 1
    Last Post: 10-29-2007, 07:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •