Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 1 Review-Spring 2007: Understanding Java Types

Back to Midterm Exam 1 Review-Spring 2007

Questions? Answers? Comments?

a) The error will be "Datatype mismatched" because the data type "integer" does not accept words.

c) I think the method should return void because this type of method usually just modifies the original version instead of creating a copy. I dont know about the static part however...I don't think it should be static...should it?

d) I think the class can extend picture and still work but I don't think its necessary to do this because the picture class and its methods are already public.

Looking at the Midterm Review I have a couple of questions.

from part (b), Problem 7 (Understanding Java Types):
I cannot clearly say why the first expression will not work. Is it because you are not allowed to declare a new variable while calling a void method?

from part(c), Problem 7 (Understanding Java Types):
I believe that you should declare the method void because there is no data to return. I am not sure however if the method should be static. If the method is static then is does not require any instances? What is an instance exactly?

from part(d), Problem 7 (Understanding Java Types):
Does this question deal with inheritance from Picture? I'm not sure what the question is asking. When you ask "and still compile?" are you asking if we will be free of errors if we attempt to compile?

b) because it says void increaseRed will still do its job-to increase red- however, it will not return the picture back (it will still compile and execute though). I do not think that you will get any error. In regards to the other one about size, it will return a picture. Also, I'm kind of confused about the feedback Prof. Guzdial gave above. If you could provide some clarification, I would be extremely grateful.

c) I'm kind of confused about the 'staticMethod()' thing Prof. Guzdial was talking about. I don't think it should be static because you do need an instance of the class. For example, you are going to use 'this' sometime in your code, right?

d). If we say PictureCollage extends Picture we are adding to what pictures will know what to do. It creates another method (PictureCollage) that pictures will now know how to do.
d.) PictureCollage can extend Picture and still compile. The collage would stil work but this is not a good idea because you really don't need your PictureCollage to inherit everything that Picture knows how to do.
d. Its because PictureCollage returns a certain picture collage. Its not a class with different components. Plus, PictureCollage is a public static void main (String[]args) so its kind of running a particular program. You can't use it to make a different collage than the one in the program. Picture is different because you use the methods in Picture on different kinds of pictures.

B. I know the void one will not work because you're saying that newpic=void which is an incorrect statement. The one that is declared Picture still wouldn't work thought because you would be redefining smallpic.
(b.) No, because void functions only change the original picture? They don't return new pictures?
d.) Okay for one, anything in a class file that has a main file needs to be static if it is used or called in "main", I know this because I've gotten errors for not making my variables in the class "TurtleDance.java" static. You can't inherit a static class, I've tried.



Link to this Page