Java Programming Quiz

August 24, 2021 | Author: Anonymous | Category: N/A
Share Embed Donate


Short Description

Download Java Programming Quiz...

Description

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 1. What is the final value of result from the follo wing code snippet? int i = 1; int [] id = new int [3]; int result = id [i]; result = result + i;

Mark for Review (1) Points

The code will compile, result has the value of 2 The code will compile, result has the value of 1 (*) The code will not compile, result has the value of 2 The code will compile, result has the value of 0  An exception is thrown. Correct 2. What is the output from the following code snippet? int[] myarray={1,2,3,4,5}; int sum=0; for (int x : myarray) sum+=x; System.out.println("sum= " + sum);

Mark for Review (1) Points

20 15 (*) 10 The code will not compile. incorrect. Refer to Section 1 Lesson 1. 3. Which two statements are access modifier keywords in Java?(Choose Two)

Mark for Review (1) Points

(Choose all correct answers) abstract public (*) protected (*) final incorrect. Refer to Section 1 Lesson 1. 4. The following code can be compiled, True/False? byte b = 1 + 1; True (*)

Mark for Review (1) Points

False incorrect. Refer to Section 1 Lesson 1. 5. Examine the partial class declaration below: class Foo{ public Foo(String s,int i ){ this(i); } public Foo(int i){ } public Foo(int i,int j){ } }

Mark for Review (1) Points

Which of following statements can not be used to create a instance of Foo? Foo f=new Foo(1); Foo f=new Foo(); (*) Foo f=new Foo(1,2); Foo f=new Foo("java",1); incorrect. Refer to Section 1 Lesson 1. Page 1 of 3

 Next Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 6. What is the output from the following code? int x=5; if (x>6) System. out. println("x>l"); else if (x>=5) System. out .println("x>=5"); else if (x=5 (*) incorrect. Refer to Section 1 Lesson 1.

Mark for Review (1) Points

7. Class Object is the root of the Java class hierarchy. True or False?

Mark for Review (1) Points

True (*) False incorrect. Refer to Section 1 Lesson 1. 8. You declare a method: public void act(Student s){}

Mark for Review (1) Points

Which of following arguments can be passed into the method? (Choose Two) (Choose all correct answers) Type of the subclass of Student (*) Type of Student class (*) Interface Type of Object class incorrect. Refer to Section 1 Lesson 1. 9. Which of the following statements about inheritance is false?

Mark for Review (1) Points

 A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Inheritance allows you to reuse the fields and methods of the super class without having to write them yourself. Inheritance allows you to minimize the amount of duplicate code in an application by sharing common code among several subclasses. Through inheritance, a parent class is a more specialized form of the child class. (*) Incorrect. Refer to Section 1 Lesson 2. 10. Unit testing can help you isolate problem quickly. True or False?

Mark for Review (1) Points

False True (*) Incorrect. Refer to Section 1 Lesson 2.

Previous Page 2 of 3  Next Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section)

11. Which of the following is not a good technique to follow when reading code written by others?

Mark for Review (1) Points

Find the author of the code and ask him how it works. (*) Perform testing. Learn the high level structure and starting point, and then figure out how it branches. Understand the constructs. Build and run the code. Incorrect. Refer to Section 1 Lesson 2. 12. What do Arrays and ArrayLists have in common? I. They both store data. II. They can both be traversed in loops. III. They both can be dynamically re-sized during execution of a program.

Mark for Review (1) Points

I only II only I and II only (*) I, II and III only None of these Correct 13. Which statement is true for the class java.util.ArrayList?

Mark for Review (1) Points

The elements in the collection are synchronized. The elements in the collection are ordered. (*) The elements in the collection are immutable. The elements in the collection are accessed using key. Incorrect. Refer to Section 1 Lesson 2. 14. Which of the following statements about arrays and ArrayLists in Java are true? I. An Array has a fixed length. II. An Array can grow and shrink dynamically as required. III. An ArrayList can store multiple object types. IV. In an ArrayList you need to know the length and the current number of elements stored. I and III only (*) II and IV only I, II, and III only I, II, III and IV None of these Correct

Mark for Review (1) Points

15. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working correctly before it is combined with other components in the system. True or false?

Mark for Review (1) Points

True (*) False Correct

Previous Page 3 of 3 Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 1. Which two statements prevent a method from being overriden? (Choose Two)

Mark for Review (1) Points

(Choose all correct answers) Final void act() {} (*) Static void act() {} Static final void act() {} (*)  Void final act() {} Final abstract void act() {} Correct 2. The following code can be compiled, True/False? byte b = 1 + 1;

Mark for Review (1) Points

True (*) False incorrect. Refer to Section 1 Lesson 1. 3. Which combination of the fo llowing overload the Student constructor?(Choose Two)

(Choose all correct answers) public Student(int x,int y){} (*) public void Student(int x, int y){} public Student(){} (*) protected int Student(){} public Object Student(int x,int y){}

Mark for Review (1) Points

incorrect. Refer to Section 1 Lesson 1. 4. Which of following relationships does not use inheritance?

Mark for Review (1) Points

 Animal and Cat People and Student Bank card and Credit Card Car and Tire (*) incorrect. Refer to Section 1 Lesson 1. 5. The following code can be compiled, True/False? b = b + 1;

Mark for Review (1) Points

True False (*) Correct Page 1 of 3

 Next Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 6. Class Object is the root of the Java class hierarchy. True or False?

Mark for Review (1) Points

True (*) False Correct 7. Which of following statments are true when you create a object from class Object at runtime as seen below. (Choose Three)  java.lang.Object obj = new java.lang.Object(); (Choose all correct answers) Memory is allocated for a new object, if available. (*)  A new instance of class Object is created. (*) Reference obj can be reassigned to any other type of object. (*) This Object instance will not be created because you never d efined class Object. incorrect. Refer to Section 1 Lesson 1.

Mark for Review (1) Points

8. You declare a method: public void act(Student s){}

Mark for Review (1) Points

Which of following arguments can be passed into the method? (Choose Two) (Choose all correct answers) Type of Student class (*) Type of Object class Type of the subclass of Student (*) Interface incorrect. Refer to Section 1 Lesson 1. 9. What do Arrays and ArrayLists have in common? I. They both store data. II. They can both be traversed in loops. III. They both can be dynamically re-sized during execution of a program.

Mark for Review (1) Points

I only II only I and II only (*) I, II and III only None of these Correct 10. When an object is able to pass on its state and behaviors to its children, this is called:

Mark for Review (1) Points

Polymorphism Isolation Encapsulation Inheritance (*) Incorrect. Refer to Section 1 Lesson 2.

Previous Page 2 of 3  Next Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 11. Unit testing can help you isolate problem quickly. True or False?

Mark for Review (1) Points

True (*) False Incorrect. Refer to Section 1 Lesson 2. 12. Which of the following statements about arrays and ArrayLists in Java are true? I. An Array has a fixed length. II. An Array can grow and shrink dynamically as required. III. An ArrayList can store multiple object types. IV. In an ArrayList you need to know the length and the current number of elements stored.

Mark for Review (1) Points

I and III only (*) II and IV only I, II, and III only I, II, III and IV None of these Incorrect. Refer to Section 1 Lesson 2. 13. Which of the following statements about unit testing is/are true I. When all unit tests succeed, you can have high confidence your code is solid. II. If a unit test fails, you donメt proceed until the code is fixed and the test succeeds. III. Unit testing can help developer find problems early in the development cycle

Mark for Review (1) Points

I only I and II only II and III only (*) I, II, and III None of these Incorrect. Refer to Section 1 Lesson 2. 14. Which of the following are important to your survival as a programmer?

Mark for Review (1) Points

Being good at reading code. Looking for opportunities to read code. Being good at testing.  All of these. (*) Incorrect. Refer to Section 1 Lesson 2. 15. The main purpose of unit testing is to verify that an individual unit (a class, in Java) is working correctly before it is combined with other components in the system. True or false? True (*) False Incorrect. Refer to Section 1 Lesson 2.

Mark for Review (1) Points

Previous Page 3 of 3 Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 1. Which ofthe following declarations are wrong?(Choose Three)

Mark for Review (1) Points

(Choose all correct answers) abstract final class Hello{} (*) abstract private void act(){} (*) protected private int id; (*) public abstract class Student{} incorrect. Refer to Section 1 Lesson 1. 2. You declare a method: public void act(Student s){}

Mark for Review (1) Points

Which of following arguments can be passed into the method? (Choose Two) (Choose all correct answers) Type of Student class (*) Interface Type of the subclass of Student (*) Type of Object class incorrect. Refer to Section 1 Lesson 1. 3. What is the output from the following code snippet? for (int i = 0; i < 10; i++) { if (i == 3) { break; } System.out.print(i);

Mark for Review (1) Points

The code will compile and print "123" The code will compile and print "012" (*) The code will compile and print "0123" The code does not compile. incorrect. Refer to Section 1 Lesson 1. 4. Which statement is incorrect regarding a constructor?

Mark for Review (1) Points

The default constructor initializes the i nstance variables. When no constructor is defined in the class, the compiler will create a default constructor. The default constructor is the no-parameter constructor.  A constructor can not return value, it must be declared as void. (*) incorrect. Refer to Section 1 Lesson 1. 5. Which two statements prevent a method from being overriden? (Choose Two)

Mark for Review (1) Points

(Choose all correct answers) Final abstract void act() {} Static final void act() {} (*)  Void final act() {} Final void act() {} (*) Static void act() {} incorrect. Refer to Section 1 Lesson 1. Page 1 of 3

 Next Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 6. Which of the following types are primitive data types? (Choose Two)

Mark for Review (1) Points

(Choose all correct answers) boolean (*) String double (*) Integer Incorrect. Refer to Section 1 Lesson 1. 7. When you instantiate a subclass, the superclass constructor will be also invoked. True or False? True (*) False

Mark for Review (1) Points

incorrect. Refer to Section 1 Lesson 1. 8. Examine the partial class declaration below: class Foo{ public Foo(String s,int i ){ this(i); } public Foo(int i){ } public Foo(int i,int j){ } }

Mark for Review (1) Points

Which of following statements can not be used to create a instance of Foo? Foo f=new Foo(1,2); Foo f=new Foo(1); Foo f=new Foo(); (*) Foo f=new Foo("java",1); incorrect. Refer to Section 1 Lesson 1. 9. Reading great code is just as important for a programmer as reading great books is for a writer. True or false?

Mark for Review (1) Points

True (*) False Incorrect. Refer to Section 1 Lesson 2. 10. Arrays have built-in operations including add, clear, contains, get and remove. True or false?

Mark for Review (0) Points

True False (*) Correct

Previous Page 2 of 3  Next Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 11. When an object is able to pass on its state and behaviors to its children, this is called:

Polymorphism

Mark for Review (1) Points

Isolation Inheritance (*) Encapsulation Incorrect. Refer to Section 1 Lesson 2. 12. Unit testing is the phase in software testing in which individual software modules are combined and tested as a whole. True or false?

Mark for Review (1) Points

True False (*) Incorrect. Refer to Section 1 Lesson 2. 13. Which of the following statements about inheritance is false?

Mark for Review (1) Points

 A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Inheritance allows you to reuse the fields and methods of the super class without having to write them yourself. Inheritance allows you to minimize the amount of duplicate code in an application by sharing common code among several subclasses. Through inheritance, a parent class is a more specialized form of the child class. (*) Incorrect. Refer to Section 1 Lesson 2. 14. What do Arrays and ArrayLists have in common? I. They both store data. II. They can both be traversed in loops. III. They both can be dynamically re-sized during execution of a program.

Mark for Review (1) Points

I only II only I and II only (*) I, II and III only None of these Correct 15. Which of the following statements about arrays and ArrayLists in Java are true? I. An Array has a fixed length. II. An Array can grow and shrink dynamically as required. III. An ArrayList can store multiple object types. IV. In an ArrayList you need to know the length and the current number of elements stored. I and III only (*) II and IV only I, II, and III only I, II, III and IV

Mark for Review (1) Points

None of these Incorrect. Refer to Section 1 Lesson 2.

Previous Page 3 of 3 Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 1. Unit testing is the phase in software testing in which individual software modules are combined and tested as a whole. True or false?

Mark for Review (1) Points

True False (*) Correct 2. Reading great code is just as important for a programmer as reading great books is for a writer. True or false?

Mark for Review (1) Points

True (*) False Incorrect. Refer to Section 1 Lesson 2. 3. Which statement is true for the class java.util.ArrayList?

Mark for Review (1) Points

The elements in the collection are accessed using key. The elements in the collection are ordered. (*) The elements in the collection are synchronized. The elements in the collection are immutable. Correct 4. In the relationship between two objects, the class that is being inherited from is called the maxi-class. True or false?

Mark for Review (1) Points

True False (*) Correct 5. Unit testing can help you isolate problem quickly. True or False?

Mark for Review (1) Points

False True (*) Correct Page 1 of 3

 Next Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 6. Which of the following is not a good technique to follow when reading code written by others?

Mark for Review (1) Points

Understand the constructs. Perform testing. Find the author of the code and ask him how it works. (*) Learn the high level structure and starting point, and then figure out how it branches. Build and run the code. Correct 7. Which of the following statements about inheritance is false?

Mark for Review (1) Points

 A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Inheritance allows you to reuse the fields and methods of the super class without having to write them yourself. Inheritance allows you to minimize the amount of duplicate code in an application by sharing common code among several subclasses. Through inheritance, a parent class is a more specialized form of the child class. (*) Correct 8. Which of following statments are true when you create a object from class Object at runtime as seen below. (Choose Three)  java.lang.Object obj = new java.lang.Object(); (Choose all correct answers) Reference obj can be reassigned to any other type of object. (*) This Object instance will not be created because you never defined class O bject.  A new instance of class Object is created. (*) Memory is allocated for a new object, if available. (*)

Mark for Review (1) Points

correct 9. What is the output from the following code snippet? String str1= "java"; String str2=new String("java"); System.out.println( str1==str2 ); System.out.println( str1==str2.intern() );

Mark for Review (1) Points

The code does not compile. The code will compile and print "true true" The code will compile and print "true false" The code will compile and print "false true" (*) The code will compile and print "false false" incorrect. Refer to Section 1 Lesson 1. 10. The following code can be compiled, True/False? byte b = 1; b = b + 1;

Mark for Review (1) Points

True False (*) Correct

Previous Page 2 of 3  Next Summary

Test: Section 1 Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 Quiz (Answer all questions in this section) 11. Examine the following Classes: Student and TestStudent What is the output from the println statement in TestStudent? public class Student { private int studentId = 0; public Student(){ studentId++; } public static int getStudentId(){ return studentId; } } public class TestStudent { public static void main(String[] args) { Student s1 = new Student(); Student s2 = new Student(); Student s3 = new Student();

Mark for Review (1) Points

 System.out.println(Student.getStudentId()); } } 3 No output. Compilation of TestStudent fails (*) 1 TestStudent will throw an exception Correct 12. Class Object is the root of the Java class hierarchy. True or False?

Mark for Review (1) Points

True (*) False Correct 13. Which two statements are access modifier keywords in Java?(Choose Two)

Mark for Review (1) Points

(Choose all correct answers) public (*) protected (*) final abstract incorrect. Refer to Section 1 Lesson 1. 14. When you instantiate a subclass, the superclass constructor will be also invoked. True or False?

Mark for Review (1) Points

True (*) False incorrect. Refer to Section 1 Lesson 1. 15. Which statement is incorrect regarding a constructor?

The default constructor is the no-parameter constructor.  A constructor can not return value, it must be declared as void. (*) When no constructor is defined in the class, the compiler will create a default constructor. The default constructor initializes the instance variables. incorrect. Refer to Section 1 Lesson 1.

Previous Page 3 of 3 Summary

Mark for Review (1) Points

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF