Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CPSC150 Exam Questions: Java Programming Fundamentals - Prof. Ming Zhang, Assignments of Computer Science

A set of multiple-choice questions from an exam covering various topics in java programming, including method calls, static methods, variables, and arguments. Students are expected to understand concepts such as passing information to methods, declaring methods, and the difference between arguments and parameters.

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-q6y
koofers-user-q6y 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC150 EH13 1
CPSC150 EH13
Q1: Information is passed to a method in:
a.the method name.
b.that method's return.
c.the called method.
d.the arguments to the method.
Q2: Programs designed for maintainability are constructed from small simple pieces or modules. Modules
in Java are called:
a.methods.
b.classes.
c.arguments.
d.both methods and classes.
Q3: A well-designed method
a.performs multiple unrelated tasks.
b.repeats code found in other methods.
c.contains thousands of lines of code.
d.performs a single, well-defined task.
Q4: To declare a method as static, place the keyword static before ________ in the method’s
declaration.
a.the method modifier.
b.the return type.
c.the method name.
d.the argument list.
Q5: Which is a correct static method call of Math class method sqrt?
a.sqrt( 900 );.
b.math.sqrt( 900 );.
c.Math.sqrt( 900 );.
d.Math math = new Math(); math.sqrt( 900 );.
Q6: Which of the following can be an argument to a method?
a.Constants.
b.Variables.
c.Expressions.
d.All of the above.
Q7: Any field declared with keyword ________ is constant.
a.static.
b.cons.
c.constant.
d.final.
Q8: Declaring main as ________ allows the JVM to invoke main without creating an instance of the
class.
a.public.
b.void.
c.static.
d.final.
pf3

Partial preview of the text

Download CPSC150 Exam Questions: Java Programming Fundamentals - Prof. Ming Zhang and more Assignments Computer Science in PDF only on Docsity!

CPSC150 EH

Q1: Information is passed to a method in: a.the method name. b.that method's return. c.the called method. d.the arguments to the method. Q2: Programs designed for maintainability are constructed from small simple pieces or modules. Modules in Java are called: a.methods. b.classes. c.arguments. d.both methods and classes. Q3: A well-designed method a.performs multiple unrelated tasks. b.repeats code found in other methods. c.contains thousands of lines of code. d.performs a single, well-defined task. Q4: To declare a method as static, place the keyword static before ________ in the method’s declaration. a.the method modifier. b.the return type. c.the method name. d.the argument list. Q5: Which is a correct static method call of Math class method sqrt? a.sqrt( 900 );. b.math.sqrt( 900 );. c.Math.sqrt( 900 );. d.Math math = new Math(); math.sqrt( 900 );. Q6: Which of the following can be an argument to a method? a.Constants. b.Variables. c.Expressions. d.All of the above. Q7: Any field declared with keyword ________ is constant. a.static. b.cons. c.constant. d.final. Q8: Declaring main as ________ allows the JVM to invoke main without creating an instance of the class. a.public. b.void. c.static. d.final.

Q9: Variables should be declared as fields only if a.they are local variables. b.they are used only within a method. c.they are required for use in more than one method or their values must be saved between calls to the class’s methods. d.they are arguments. Q10: Consider the following Java statements: int x = 9; double y = 5.3; result = calculateValue( x, y ); Which of the following statements is false? a.A method is called with its name and parentheses. b.x and y are parameters. c.Copies of x and y are passed to the method calculateValue(). d.x and y are arguments. Q11: The parameter list in the method header and the arguments in the method call must agree in: a.number b.type c.order d.all of the above Q12: A static method can ________. a.call only other static methods of the same class directly. b.manipulate only static fields in the same class directly. c.be called using the class name and a dot (.). d.All of the above. Q13: Which statement is false? a.If a method does not return a value, the return-value-type in the method declaration can be omitted. b.Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error. c.Redeclaring a method parameter as a local variable in the method’s body is a compilation error. d.Forgetting to return a value from a method that should return a value is a compilation error. Q14: Which statement is not true. a.The Java API consists of packages. b.The Java API is provided to keep programmers from "reinventing the wheel." c.The Java API consists of import declarations. d.The class javax.swing.JApplet is part of the Java API. Q15: Which of the following is not a package in the Java API? a.java.component. b.java.awt. c.javax.swing.event. d.java.lang. Q16: Write a method multiple that determines, for a pair of integers, whether the second interger is a multiple of the first. The method should take two integer arguments and return true if the second is a multiple of the first and false otherwise. Incorporate this method into an application thatinputs a series of pairs of integers (one pair at a time) and determines whether the second value is each pair is a multiple of the first.