JAVA Programming Language Homework II Student ID: Name:

Similar documents
JAVA Programming Language Homework I - Nested Class

University of Palestine. Mid Exam Total Grade: 100

PROGRAMMING FUNDAMENTALS

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

Part (II): In the body method main : Write the call to method formatname and have the return value stored in the variable formatted.

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

JAVA Programming Language Homework I - OO concept

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

Following is the general form of a typical decision making structure found in most of the programming languages:

Domain-Driven Design Activity

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Some Sample AP Computer Science A Questions - Solutions

Introduction to Java

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Introduction to Computer Science II (CSI 1101)

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

Java Identifiers, Data Types & Variables

Arrays. COMS W1007 Introduction to Computer Science. Christopher Conway 10 June 2003

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

CS180. Exam 1 Review

Computer Programming, I. Laboratory Manual. Final Exam Solution

d. If a is false and b is false then the output is "ELSE" Answer?

Problem Grade Total

CPSC 219 Extra review and solutions

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.

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

JAVA OPERATORS GENERAL

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

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

I. True/False: (2 points each)

Object Oriented Programming 2014/15. Final Exam July 3, 2015

Introduction to Computer Science Unit 2. Notes

Selected Questions from by Nageshwara Rao

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Oracle 1Z Java SE 8 Programmer I. Download Full Version :

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Distributed Systems Recitation 1. Tamim Jabban

Solutions to Sample JAC444 Midterm Test

Lecture Set 4: More About Methods and More About Operators

Computational Expression

More Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects.

PASS4TEST IT 인증시험덤프전문사이트

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.

CS 101 Fall 2005 Midterm 2 Name: ID:

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

Supplementary Test 1

Programming Languages and Techniques (CIS120)

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Midterm Exam 2 CS 455, Spring 2015

CSC 1351: Final. The code compiles, but when it runs it throws a ArrayIndexOutOfBoundsException

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

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

COE318 Lecture Notes Week 4 (Sept 26, 2011)

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

Tutorial 03. Exercise 1: CSC111 Computer Programming I

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

Final Examination Semester 2 / Year 2011

NATIONAL UNIVERSITY OF SINGAPORE

Lecture Set 4: More About Methods and More About Operators

Java Simple Data Types

Introduction to Programming (CS112): Sample

Unit 4: Classes and Objects Notes

Chair of Software Engineering Java and C# in Depth

Variable initialization and assignment

Fall 2017 Mentoring 9: October 23, Min-Heapify This. Level order, bubbling up. Level order, bubbling down. Reverse level order, bubbling up

MIDTERM REVIEW. midterminformation.htm

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

Midterm Exam CS 251, Intermediate Programming October 8, 2014

Exercise 6 Multiple Inheritance, Multiple Dispatch and Linearization November 3, 2017

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Administrivia. Last modified: Fri Aug 25 10:59: CS61B: Lecture #2 1

Midterm Examination (MTA)

More types, Methods, Conditionals. ARCS Lab.

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

CS 101 Exam 2 Spring Id Name

( &% class MyClass { }

CS 1331 Exam 1 ANSWER KEY

Fundamentals of Programming Data Types & Methods

Practice Questions for Chapter 9

Visual Programming. Lecture 2: More types, Methods, Conditionals

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

CS 11 java track: lecture 1

The class Object. Lecture CS1122 Summer 2008

ECE 461 Fall 2011, Final Exam

CSC 231 DYNAMIC PROGRAMMING HOMEWORK Find the optimal order, and its optimal cost, for evaluating the products A 1 A 2 A 3 A 4

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

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

Unit 10: Sorting/Searching/Recursion

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Getting started with Java

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

CS171:Introduction to Computer Science II

Accurate study guides, High passing rate! Testhorse provides update free of charge in one year!

Transcription:

JAVA Programming Language Homework II Student ID: Name: 1. Given the following Java code: 1. class A { 2. public static void main (String[] args) { 3. Byte tmp1 = new Byte( 1 ); 4. Byte tmp2 = new Byte( 1 ); 5. if (tmp1 == tmp2) System.out.println( true, ); 6. else System.out.println( false, ); 7. if (tmp1.equals(tmp2)) System.out.println( true, ); 8. else System.out.println( false, ); 10. } A. false, false B. false, true C. true, false D. true, true E. None of the above 2. Given the following Java code: 1. class A { 2. final String s1 = A.s1 ; 3. final String S2 = Aa.s1 ; 4. class B { 5. String s1; 6. void m( ) {System.out.println(???);} 7. void n( ) {System.out.println( B );} 9. public static void main(string args[]) { 10. A g = new A( ); 11. g.new B( ).m( ); 12. }

13. } What field access expression could be used in place of??? above to cause the program to print A.s1? A. s1 B. A.s1 C. ((A)this).s1 D. A.this.s1 E. None of the above 3. Given the following Java code: 1. Integer i = new Integer(42); 2. Long l = new Long(42); 3. Double d = new Double(42.0); Which two expressions evaluate to True? A. (i== 1) B. (i == d) C. (i.equals(42)) D. (i.equals(d)) E. (d.equals(i)) 4. Given the following Java code: 11. class A { 12. public static final int a = 1; 13. protected static int b=2; 14. int c=3; 15. static class B { 16. int d=a; 17. int e=b; 18. int f=c; 1 20. class C { 21. int g=a;

22. int h=b; 23. int i=c; 24. } 25. } F. Compilation Error at line 10. G. Compilation Error at line 8. H. Compilation Error at line 2. I. Run without any problem. J. None of the above. 5. Given the following Java code: 1. class B { 2. private int x = 2; 3. static A a1 = new A(2,1) { 4. public A(int tmp) {x(tmp); y(tmp);}; 5. public int m() {return x()+y();} 6. }; 7. public static void main(string[] args) { 8. System.out.print(a1.m()); 10. } 11. abstract class A { 12. private int x = 4; 13. private int y = 2; 14. private int z = 6; 15. public int x() {return x;} 16. public void x(int x) {this.x = x;} 17. public int y() {return y;} 18. public void y(int y) {this.y = y;} 19. public abstract int m(); 20. } A. Prints: 8

B. Prints: 3122 C. Compilation fails D. Run-time error E. None of the above 6. Given the following Java code: 1. public class Foo { 2. Foo() {System.out.println( foo );} 3. class Bar { 4. Bar() {System.out.println( bar );} 5. public void go() {System.out.println( hi );} 6. } 7. public static void main (String[] args) { 8. Foo f = new Foo(); 9. f.makebar(); 10. } 11. void makebar() { 12. (new Bar() {}).go(); 13. } 14. } A. Run-time error. B. Compilation fails. C. foobarhi D. barhi E. hi 7. Given the following Java code: 1. public class HorseTest { 2. public static void main (String[] args) { 3. class Horse { 4. public String name;

5. public Horse(String s) { 6. name = s; 7. } 9. Object obj = new Horse( Zippo ); 10. Horse h = (Horse) obj; 11. System.out.println(h.name); 12. } 13. } A. Compilation Error at line 3 B. Compilation Error at line 9 C. Compilation Error at line 10 D. Compilation Error at line 11 E. Zippo 8. Given the following Java code: 1. public class HorseTest { 2. public static void main (String[] args) { 3. class Horse { 4. public String name; 5. public Horse(String s) { 6. name = s; 7. } 9. Object obj = new Horse( Zippo ); 10. System.out.println(obj.name); 11. } 12. } A. Compilation Error at line 3 B. Compilation Error at line 9 C. Compilation Error at line 10

D. Compilation Error at line 11 E. Zippo 9. Given the following Java code: 1. public abstract class AbstractTest { 2. public int getnum() { 3. return 45; 4. } 5. public abstract class Bar { 6. public int getnum() { 7. return 38; 10. public static void main (String[] args) { 11. AbstractTest t = new AbstractTest() { 12. public int getnum() { 13. rerurn 22; 14. } 15. }; 16. AbstractTest.Bar f = t.new Bar() { 17. public int getnum() { 18. return 57; 1 20. }; 21. System.out,println(f.getNum() + + t.getnum()); 22. } 23. } A. 57 22 B. 45 38 C. 45 57 D. Compilation fails E. None of the above

10. Given the following Java code: 1. public class TestObj { 2. public static void main (String [] args) { 3. Object o = new Object() { 4. public boolean equals(object obj) { 5. return true; 6. } 7. } 8. System.out.println(o.equals("Fred")); 10. } A. true B. Compilation fails because of an error on line 3. C. Compilation fails because of an error on line 4. D. Compilation fails because of an error on line 8. E. Compilation fails because of an error on a line other than 3, 4, or 8. 11. Given the following Java code: 1. class Foo { 2. class Bar{ } 3. } 4. class Test { 5. public static void main (String [] args) { 6. Foo f = new Foo(); 7. // Insert code here Which statement, inserted at line 7, creates an instance of Bar? A. Foo.Bar b= new Foo.Bar(); B. Foo.Bar b = f.new Bar(); C. Bar b = new f.bar(); D. Bar b = f.new Bar();

E. Foo.Bar b = new f.bar();