

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A quiz on java programming concepts, including matching questions about objects, variables, methods, and access modifiers. Students are required to answer questions about data in objects, messages sent to objects, creating new objects, initializing objects, class-wide data, and accessing instance variables and methods. The document also includes a question asking students to write an accessor method for a student class instance variable and two coding questions to check the compilation of given java methods.
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


This quiz is to be taken by yourself with closed books, closed notes, no electronic devices.
Matching:
_____ Data in an object
_____ Messages sent to objects
_____ A way to create a new object
_____ Ways to initialize a newly created object
_____ Class-wide data accessible by all objects of the same type
_____ Must be the same name as the class name
_____ Refers to the object being send a message / called object
_____ Must have a return type
_____ If uninitialized, has no default value (garbage)
_____ Must not have a return type
_____ If uninitialized, has a known default value
_____ Can only be accessed by its simple name, no reference qualifier
_____ By Java naming convention, starts with an uppercase letter
_____ A "better" return type for mutators/setters
_____ Methods or constructors that have the same name but differ in the number, type, or order of parameters
_____ Return type for accessors/getters
_____ Most instance variables should be this access mode
_____ Most methods and constructors should be this access mode
A) private B) instance method C) class / class name D) boolean E) instance variable F) new operator G) this H) static variable I) Object J) void K) type of the instance variable accessed L) constructor M) overload N) public O) local variable
[You do not need to use all letters. Some letters will need to be used more than once.]
Assume there is a class named Student with an instance variable defined as
String name;
Write the accessor/getter method for the name variable above.
____________ ___________________() { ____________ ________________ ; }
Will the following code compile? ___________ If not, what change do you need to make to the method header (not the body) so that it will compile? Explain. Be specific.
public int test( double x ) { System.out.println( "In test" ); }
Will the following code compile? ___________ If not, what change do you need to make to the method header (not the body) so that it will compile? Explain. Be specific.
public String test( double x ) { System.out.println( "In test" ); return x + x; }
What question(s) would you like to see on the Final Exam?