Review Ch 5 static Multiple Choice Test Creating Class Methods

Similar documents
Final Examination Review

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

b. Suppose you enter input from the console, when you run the program. What is the output?

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Methods. Bok, Jong Soon

PROGRAMMING FUNDAMENTALS

Building Java Programs

Building Java Programs

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

( &% class MyClass { }

Strings, Strings and characters, String class methods. JAVA Standard Edition

APCS Semester #1 Final Exam Practice Problems

Visual Programming. Lecture 3: Loops, Arrays. Mahmoud El-Gayyar

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

Selected Questions from by Nageshwara Rao

Chapters 1-4 Summary. Syntax - Java or C? Syntax - Java or C?

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

COMP 110/L Lecture 13. Kyle Dewey

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

- Thus there is a String class (a large class)

2.8. Decision Making: Equality and Relational Operators

Lecture 2 Tao Wang 1

Building Java Programs

Chapter 3: Operators, Expressions and Type Conversion

4 Programming Fundamentals. Introduction to Programming 1 1

Introduction to Programming Using Java (98-388)

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

CIS October 19, 2017

Course Outline. Introduction to java

Lec 3. Compilers, Debugging, Hello World, and Variables

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

Variables, Types, Operations on Numbers

Java Basics Programming Fundamentals

Handout 7. Defining Classes part 1. Instance variables and instance methods.

Full file at

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

1. Find the output of following java program. class MainClass { public static void main (String arg[])

COMP 110 Project 1 Programming Project Warm-Up Exercise

Java Identifiers, Data Types & Variables

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

Zheng-Liang Lu Java Programming 45 / 79

Section 2.2 Your First Program in Java: Printing a Line of Text

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

CS 112 Introduction to Programming

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example

Chapter 2: Programming Concepts

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Full file at

Lecture Set 4: More About Methods and More About Operators

Handout 4 Conditionals. Boolean Expressions.

Lecture 5: Methods CS2301

CSc Introduction to Computing

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Programming Basics. Digital Urban Visualization. People as Flows. ia

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Chapter 4 Defining Classes I

Creating a C++ Program

Java Programming for Selenium

Instance Method Development Demo

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Introduction to C++ with content from

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

CS 177 Spring 2010 Exam I

class objects instances Fields Constructors Methods static

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Datatypes, Variables, and Operations

CIS March 1, 2018

*Java has included a feature that simplifies the creation of

AP COMPUTER SCIENCE AB 2006 SCORING GUIDELINES

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Programming with Java

Methods. Methods. Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria

Fundamentals of Programming Data Types & Methods

Java Bytecode (binary file)

4. If the following Java statements are executed, what will be displayed?

Final Exam COMP Fall 2004 Dec 16, 2004

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Topic 4 Expressions and variables

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

TUGCE KEMEROZ - ASLI OZKAN - AYSE TARTAN. Week 12/02/ /02/2007 Lecture Notes:

Language Proposal: tail

Object-Oriented Programming (OOP) Basics. CSCI 161 Introduction to Programming I

We have written lots of code so far It has all been inside of the main() method What about a big program? The main() method is going to get really

CS 177 Recitation. Week 1 Intro to Java

CPSC 219 Extra review and solutions

Computational Expression

Loops. CSE 114, Computer Science 1 Stony Brook University

Getting started with Java

Transcription:

Review Ch 5 static Multiple Choice Test Creating Class Methods 01. A class method call always requires that the class identifier precedes the method identifier. may be called with the method identifier if in the same.java file. is only possible after a new object is constructed. uses the class identifier only for readability. 10. Which of the following Java keywords are used frequently in the declaration of a class method? void public static All of the above 11. Consider the Java program below. public class Q11 public static void main(string args[ ]) boohiss(); // line 1 boohiss.q11(); // line 2 Q11.boohiss(); // line 3 public static void boohiss() System.out.println("Calling boohiss"); Which of the statements in the main method is a proper method call? Line 1 only Line 2 only Line 3 only Lines 1 and 3 Exposure Java 2013, APCS Edition Chapter 7 Test Page 1 Updated: 10-29-13

100. Consider the Java program below. public class Q12A public static void main(string args[ ]) boohiss(); // line 1 Q12A.boohiss.(); // line 2 Q12B.boohiss(); // line 3 class Q12B public static void boohiss() System.out.println("Calling boohiss"); Which of the statements in the main method is a proper method call? Line 1 only Line 3 only Lines 1 and 2 Lines 1 and 3 Exposure Java 2013, APCS Edition Chapter 7 Test Page 2 Updated: 10-29-13

101. What is the output of the following program? public class Q13 method1(); public static void method1() method2(); System.out.println("Calling method 1"); public static void method2() method3(); System.out.println(""); public static void method3() System.out.println(""); Calling method 1 Calling method 1 Calling method 1 Exposure Java 2013, APCS Edition Chapter 7 Test Page 3 Updated: 10-29-13

110. What is the output of the following program? public class Q14 method1(); method3(); method2(); public static void method1() System.out.println("Calling method 1"); public static void method2() System.out.println(""); public static void method3() System.out.println(""); Calling method 1 Calling method 1 Calling method 1 Exposure Java 2013, APCS Edition Chapter 7 Test Page 4 Updated: 10-29-13

111. What is the output of the following program? public class Q15 method1(); method2(); method3(); class Tango public static void method1() System.out.println("Calling method 1"); public static void method2() System.out.println(""); public static void method3() System.out.println(""); Calling method 1 Calling method 1 Calling method 1 Exposure Java 2013, APCS Edition Chapter 7 Test Page 5 Updated: 10-29-13

1000. What is the output of the following program? public class Q16 Tango.method1(); class Tango public static void method1() method2(); System.out.println("Calling method 1"); public static void method2() System.out.println(""); Method3(); public static void method3() System.out.println(""); Calling method 1 Calling method 1 Calling method 1 Exposure Java 2013, APCS Edition Chapter 7 Test Page 6 Updated: 10-29-13

1001. Which of the following statements is true about the use of parameters with Java methods? Methods without parameters can compile, but will not execute correctly. All method declarations require parameters. Many methods use parameters. The use of parameters is optional to increase program readability. 1010. Which of the following statements is true about a method declaration with multiple parameters? All parameters must be the same data type. All parameters must be different data types. Parameter data types may be the same or they may be different. The parameter declarations depend on the method call. 1011. Which of the following method headings uses proper parameter declarations? public static void guess(double rate, double hours, int deductions); public static void guess(double rate, hours, int deductions); public static void guess(rate, hours, deductions); public static void guess(7.85, 42.5, 3); 1100. Which of the following method calls might use argumentss correctly? (arguments in call, parameters in definition) guess(double rate, double hours, int deductions); guess(double rate, hours, int deductions); guess(int rate, hours, deductions); guess(7.85, 42.5, 3); 1101. The arguments in the method call and the parameters in the method heading must be the same I. quantity. II. sequence. III. datetype. (E) I only II only I & II only II & III only I, II & III Exposure Java 2013, APCS Edition Chapter 7 Test Page 7 Updated: 10-29-13

1110. What is the output of the following program? public class Q23 Q23.method1(1); method2(2); public static void method1(int n) System.out.println("Calling method " + n); public static void method2(int n) System.out.println("Calling method " + n); method3(n); public static void method3(int n) System.out.println("Calling method " + n); Calling method 1 Calling method 1 Calling method 1 Exposure Java 2013, APCS Edition Chapter 7 Test Page 8 Updated: 10-29-13

1111. What is the output of the following program? public class Q24 int n = 4; method1(n); method2(n + 2, 3); method3(n + n); public static void method1(int x) System.out.println("x = " + x); public static void method2(int x, int y) System.out.println("x + y = " + (x + y) ); public static void method3(int n) int x = 4; System.out.println("x = " + n+x); 4 63 8 x = 4 x + y = 9 x = 12 x = 4 x + y = 9 x = 8 4 Exposure Java 2013, APCS Edition Chapter 7 Test Page 9 Updated: 10-29-13

hex 0010. What distinguishes the declaration of a mutator method? The public keyword in the method heading The static keyword in the method heading The void keyword in the method heading The main keyword in the method heading 0011. What distinguishes the declaration of an accessor method? The return keyword in the method body The static keyword in the method heading The data type declaration in the method heading (do not confuse with parameter data types) Both A and C 0012. What distinguishes a call to a mutator method? The method call is the only part of a complete program statement. The method call provides a value, which is used in the program statement. The method call includes the void keyword. The method call includes the return keyword. 0013. What distinguishes a call to a accessor method? The method call is the only part of a complete program statement. The method call provides a value, which is used in the program statement. The method call includes the void keyword. The method call includes the return keyword. 0014. What distinguishes a class method definition? The public keyword in the method heading The static keyword in the method heading The void keyword in the method heading The main keyword in the method heading Exposure Java 2013, APCS Edition Chapter 7 Test Page 10 Updated: 10-29-13

0015. What is the output of the following program? public class Q29 int x = 25; int y = 10; Calc.add(x,y); Calc.sub(x,y); Calc.mul(x,y); Calc.div(x,y); class Calc public static void add(int p, int q) int result = p + q; System.out.println(p + " + " + q + " = " + result); public static void sub(int p, int q) int result = p - q; System.out.println(p + " - " + q + " = " + result); public static void mul(int p, int q) int result = p * q; System.out.println(p + " * " + q + " = " + result); public static void div(int p, int q) int result = p / q; System.out.println(p + " / " + q + " = " + result); 25 + 10 25 + 10 = 35 35 25-10 25-10 = 15 15 25 * 10 25 * 10 = 250 250 25 / 10 25 / 10 = 2 2 Exposure Java 2013, APCS Edition Chapter 7 Test Page 11 Updated: 10-29-13

0016. What is the output of the following program? public class Q30 int x = 25; int y = 10; System.out.println(Calc.add(x,y)); System.out.println(Calc.sub(x,y)); System.out.println(Calc.mul(x,y)); System.out.println(Calc.div(x,y)); class Calc public static void add(int p, int q) int result = p + q; System.out.println(p + " + " + q + " = " + result); public static void sub(int p, int q) int result = p - q; System.out.println(p + " - " + q + " = " + result); public static void mul(int p, int q) int result = p * q; System.out.println(p + " * " + q + " = " + result); public static void div(int p, int q) int result = p / q; System.out.println(p + " / " + q + " = " + result); 25 + 10 25 + 10 = 35 35 25-10 25-10 = 15 15 25 * 10 25 * 10 = 250 250 25 / 10 25 / 10 = 2 2 Exposure Java 2013, APCS Edition Chapter 7 Test Page 12 Updated: 10-29-13

0017. What is the output of the following program? public class Q31 int x = 25; int y = 10; System.out.println(x + " + " + y + " = " + Calc.add(x,y)); System.out.println(x + " - " + y + " = " + Calc.sub(x,y)); System.out.println(x + " * " + y + " = " + Calc.mul(x,y)); System.out.println(x + " / " + y + " = " + Calc.div(x,y)); class Calc public static int add(int p, int q) int result = p + q; return result; public static int sub(int p, int q) int result = p - q; return result; public static int mul(int p, int q) return p * q; public static int div(int p, int q) return p / q; 25 + 10 25 + 10 = 35 35 25-10 25-10 = 15 15 25 * 10 25 * 10 = 250 250 25 / 10 25 / 10 = 2 2 Exposure Java 2013, APCS Edition Chapter 7 Test Page 13 Updated: 10-29-13

0018. What is the output of the following program? public class Q32 int x = 25; int y = 10; Calc.add(x,y); Calc.sub(x,y); Calc.mul(x,y); Calc.div(x,y); class Calc public static int add(int p, int q) int result = p + q; return result; public static int sub(int p, int q) int result = p - q; return result; public static int mul(int p, int q) return p * q; public static int div(int p, int q) return p / q; 25 + 10 25 + 10 = 35 35 25-10 25-10 = 15 15 25 * 10 25 * 10 = 250 250 25 / 10 25 / 10 = 2 2 No output Exposure Java 2013, APCS Edition Chapter 7 Test Page 14 Updated: 10-29-13

0019. What is the output of the following program? public class Q33 int x = 25; int y = 10; Calc.add(x,y); Calc.sub(x,y); Calc.mul(x,y); Calc.div(x,y); class Calc public static void add(int p, int q) int result = p - q; System.out.println(p + " - " + q + " = " + result); public static void sub(int p, int q) int result = p + q; System.out.println(p + " + " + q + " = " + result); public static void mul(int p, int q) int result = p / q; System.out.println(p + " / " + q + " = " + result); public static void div(int p, int q) int result = p * q; System.out.println(p + " * " + q + " = " + result); 25 + 10 = 35 25 + 10 = 15 25-10 = 15 1 25-10 = 15 25-10 = 35 25 + 10 = 35 2 25 * 10 = 250 25 * 10 = 2 25 / 10 = 2 3 25 / 10 = 2 25 / 10 = 250 25 * 10 = 250 4 (E) Exposure Java 2013, APCS Edition Chapter 7 Test Page 15 Updated: 10-29-13

001A. What is the output of the following program? public class Q34 int x = 25; int y = 10; System.out.println(x + " + " + y + " = " + Calc.add(x,y)); System.out.println(x + " - " + y + " = " + Calc.sub(x,y)); System.out.println(x + " * " + y + " = " + Calc.mul(x,y)); System.out.println(x + " / " + y + " = " + Calc.div(x,y)); class Calc public static int add(int p, int q) int result = p q; return result; public static int sub(int p, int q) int result = p + q; return result; public static int mul(int p, int q) return p / q; public static int div(int p, int q) return p * q; 25 + 10 = 35 25 + 10 = 15 25-10 = 15 1 25-10 = 15 25-10 = 35 25 + 10 = 35 2 25 * 10 = 250 25 * 10 = 2 25 / 10 = 2 3 25 / 10 = 2 25 / 10 = 250 25 * 10 = 250 4 (E) Exposure Java 2013, APCS Edition Chapter 7 Test Page 16 Updated: 10-29-13

001B. What is the output of the following program? public class Q35 int x = 25; int y = 10; System.out.println(Calc.add(x,y)); System.out.println(Calc.sub(x,y)); System.out.println(Calc.mul(x,y)); System.out.println(Calc.div(x,y)); class Calc public static String add(int p, int q) int sum = p + q; String result = p + " + " + q + " = " + sum; return result; public static String sub(int p, int q) int diff = p - q; String result = p + " - " + q + " = " + diff; return result; public static String mul(int p, int q) int prod = p * q; String result = p + " * " + q + " = " + prod; return result; public static String div(int p, int q) int quot = p + q; String result = p + " / " + q + " = " + quot; return result; 25 + 10 = 35 25 + 10 = 15 25-10 = 15 1 25-10 = 15 25-10 = 35 25 + 10 = 35 2 25 * 10 = 250 25 * 10 = 2 25 / 10 = 2 3 25 / 10 = 2 25 / 10 = 250 25 * 10 = 250 4 (E) Exposure Java 2013, APCS Edition Chapter 7 Test Page 17 Updated: 10-29-13

001C. What is the output of the following program? public class Q36 int x = 25; int y = 10; System.out.println(Calc.add(x,y)); System.out.println(Calc.sub(x,y)); System.out.println(Calc.mul(x,y)); System.out.println(Calc.div(x,y)); class Calc public static String add(int p, int q) int sum = p + q; String result = p + " + " + q + " = " + sum; return 1 ; public static String sub(int p, int q) int diff = p - q; String result = p + " - " + q + " = " + diff; return 2 ; public static String mul(int p, int q) int prod = p * q; String result = p + " * " + q + " = " + prod; return 3 ; public static String div(int p, int q) int quot = p + q; String result = p + " / " + q + " = " + quot; return 4 ; 25 + 10 = 35 25 + 10 = 15 25-10 = 15 1 25-10 = 15 25-10 = 35 25 + 10 = 35 2 25 * 10 = 250 25 * 10 = 2 25 / 10 = 2 3 25 / 10 = 2 25 / 10 = 250 25 * 10 = 250 4 (E) Exposure Java 2013, APCS Edition Chapter 7 Test Page 18 Updated: 10-29-13

001D. The Java compiler checks for (E) correct program syntax. correct program logic. consistent program statement indentations. the use of meaningful variable identifiers. the proper implementation of methods. 001E. Which of the following are fundamental program design considerations? (E) Programs should use mnemonic identifiers. Control structures should use a consistent indentation style. Specific tasks should be placed in procedures or functions, called methods. The main method should be used for program sequence, not large numbers of program statements. All of the above 001F. Which of the following variable names is not a mnemonic identifier? (E) netpay deductions k checkingbalance grosspay 0020. Which of the following boohiss methods will receive and integer and return triple that amount? public static int boohiss() return j + j + j; public static void boohiss( int j ) return j + j + j; public static int boohiss( char j ) return 3 * j; public static int boohiss( int j ) return 3 * j; 0021. Which of the following boohiss methods will receive 1 character and return its ASCII value? public static int boohiss( char c ) return (int) c; public static char boohiss( int c ) return (int) c; public static char boohiss( char c ) return (int) c; public static char boohiss( int c ) return (char) c; (E) public static int boohiss( char c ) return (char) c; Exposure Java 2013, APCS Edition Chapter 7 Test Page 19 Updated: 10-29-13

0022. Which of the following boohiss methods will receive 1 integer and return the next one? public static char boohiss( char c ) c++; return c; public static char boohiss( char c ) return c++; public static int boohiss( int c ) c++; return c; public static int boohiss( int c ) return c++; 0023. Which of the following boohiss methods will receive 1 character and return the next one? public static char boohiss( char c ) c++; return c; public static char boohiss( char c ) return c++; public static int boohiss( int c ) c++; return c; public static int boohiss( int c ) return c++; 0024. What is the output of the following program? public class Q59 method(3); method(2); method(1); public static void method(int n) System.out.println("Calling method " + n); Calling method 1 Calling method 1 Calling method 1 Error Message Exposure Java 2013, APCS Edition Chapter 7 Test Page 20 Updated: 10-29-13