JavaFinal_Professor_Weng

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which one is correct? a. float f = 4; b. int i = 10.1; c. int a = (float) 3.14; d. float f = 3.0; e. float f = (double) 3.14;

A float has a higher precision than int. float f = 4;

Which one is not a typical element to be seen in a class?

API

Given a statement "int z = 100 % 7 == (10 + 2) / 5 ? 1 : 0;", what is the value of z? None of them Compile error Runtime error 1 0

According to the type strong characteristics of Java, we have both 100 % 7 and (10 + 2) / 5 to be equal to 2. answer is 1

Which programming language was under contract to the United States Department of Defense (DoD)?

Ada

How many bytes are consumed by a pointer? 3 2 8 4 1

An integer of 4 bytes is used as an ID. 4 is answer

Which statement is correct? None of them float f = 3.5 * 4; byte b = 100 * 1000; int k = 15 / 4; int k = (double) 4 * (int) 4.5;

int k = 15 / 4;

Declare a variable w of type "int" and add a single line comment "w is for Width" at the end of the declaration.

int w; // w is for Width B

In this conditional statement, what would be the predicate results for variable a to be a double primitive type? if ((a = (2 + 1) / 2) true of false

true a = 1.0

Which programming language is not an object oriented programming language?

C

What type of calling passes a primitive data? a.. Call-by-value b. Call-by-reference c. Both e. None of them

Call-by-value passes in a data value, while call-by-reference passes in a pointer.

What type of calling passes a primitive data? Call-by-reference None of them Call-by-value Both

Call-by-value passes in a data value, while call-by-reference passes in a pointer. Call-by-value is answer

What will be the value of y for this given statement "int y = 3.0 + 2 * 3"? a. 0 b. None of them c. 9.0 d. 15 e. 9

Cannot assign high precision value to low precision variable. None of them

For the acronym of the 10 important OOD concepts, what does the "E" stand for?

Encapsulation

Which one is not one of the reasons that Java is chosen as the OO design language for this class?

Faster than the C language

Which statement is incorrect? public class MyProg { public static void main(String[] args) { 1. int i = 1; 2. while (i++ < 5) { 3. System.out.println(i); } 4. int i = -10; } } None of them 2 1 3 4

Statement 1 has declared i. Statement 4 should not re-declare it in the same method block. 4

Which one is correct? a.Classes cannot have methods. b.Structural languages can restrict the method calls. c.Structs do not have methods. d.None of them e.Objects can call any methods.

Structs do not have methods.

In this conditional statement, what would be the predicate results for variable a to be 4.0? if ((int)(a += 10 * 2)

false (int)(4.5 + 20) is equal to 24, which is less or equal to 24.

Only _ and $ acceptable front of class name !!!!

# Not acceptable !!!!

What is the result of "int z = 10 & 13"? a. z = 1 b. z = 2 c. z = 4 d. z = 8 e. z = 6

1010 & 1101 = 1000 in binary mode. z = 8

Show the output of this program. for(int j = 1; j <= 2; j++){ for (int i = 1; i <= 4; i++){ if (i == 2) break; System.out.print( j ); } }

12

A smart phone has features of phone calling and apps. Which concept is good to be applied to design a new smart phone with more apps?

Inheritance

Which programming language is compiled to bytecode to run on the virtual machine?

Java

How many local, instance and class variables are available, respectively? public class Test { int i = 1; int j = 2; static int k = 3; public static void test1( ) { int l = 4; Test test = new Test(); } public void test2( ) { } } ________________________________________________________________________ public class RunTest { public static void main(String[] args) { RunTest runTest = new RunTest(); } } a.2, 2, 1 b.2, 3, 1 c. 3, 1, 2 d.1, 2, 3 e.4, 2, 1

Local has 4: args, l, test and runTest. Instance has 2: i and j. Class has 1: k. 4, 2, 1 is answer

Which one is not an acceptable class identifier name? $People None of them P2eople _People People

None of them

To have good encapsulation, which attribute is less likely to be in the Pet class but the Owner class instead?

Phone

A class may delegate to other classes to perform computations. Which concept depicts the dependence among classes?

Relationships

Which of the following supports multiple inheritances? a. None of them b. Class c. Interface d. Abstract class e. All of them

Since methods in interface have no implementation, multiple inheritances will not cause a problem on choosing the method to be run. Interface is answer

Which one is correct? Objects can call any methods. Structural languages can restrict the method calls. Classes cannot have methods. Structs cannot have methods. None of them

Structs only have attributes declared.OO programming languages typically run slower and consume more memory. Structs cannot have methods.

How many rows of "OK" will be printed? for(int i = 0; i < 2; i++){ for(int j = 0; j < 2; j++){ System.out.println("OK"); if(j == i) break; } System.out.println("OK"); } 2 3 5 4 6

The break depends on the values of both i and j. 5 is answer

Which one is correct when handling variable-length argument lists? a.Overloading is the best and flexible way. b.Ellipsis is concise. c.None of them d.Array is not doable for this purpose. e.Ellipsis can appear multiple times in a method.

The ellipsis is a concise way for this purpose but can only appear once in a method. Ellipsis is concise. is answer

For the interface I1 below, which statement is invalid? public interface I1{ int i; int j = 5; public getVal(); int getResult(Student s); } a. getVal() needs code implementation. b. getResult method accepts a reference data type parameter. c. getVal() requires a return type. d. j can be changed to be a different value. e. i must be assigned with a numeric integer value.

The getVal method cannot have code implementation, because it is declared in an interface. getVal() needs code implementation.

Which one is incorrect? public class MyProg { 1. int k = 10; int i = 5; public static void main(String[] args) { 2. int k = 15; 3. if (k > 5) { 4. int i = this.k+1; System.out.println(i); } } } None of them Statement 1 Statement 2 Statement 4 Statement 3

The keyword "this" cannot be used in a class (static) method. Statement 4 is answer

Which one violates the naming convention for a class name? a. studentReport b. _Student c. None of them d. Student_Report e. Student

The letter s should be upper case to be StudentReport. studentReport is answer

Which statement is incorrect? public class MyProg { public static void main(String[] args) { 1. int k = 5; 2. if(k - 3 > 0) { 3. int i = k; } 4. System.out.println(i); } } a. 1 b. 4 c. None of them d. 3 e. 2

The local variable i is declared in the if sub block and is not known outside the sub block. answer is 4

Given int a = 3 and int b = 2, what is the result of a / b? None of them 1.0 1.5 1 1.0f

Type int divided by int remains an int. So, the fraction is ignored. 1

The absolute function in Math accepts a double as argument. Which output method declaration is not ok for performing Math.abs(output() + 1)? 정답 public void output() public char output() public int output() public float output() public byte output()

The method declaration returns void, which cannot be used for math computation. public void output() is answer

Which Java edition is good for developing mobile device applications?

The micro edition is for this purpose. Java ME

What is the output of the following miss aligned code? int k = 5; int val = 20; if (k > 10) { val = k * 2; ++val; System.out.println(val); } a. 5 b.10 c.6 d.None of them e.11

The println method will not be executed. Hint: properly indent the code. None of them

Which one cannot output "Width = 3, Height = 4, Depth = 5"? a. System.out.printf("Width = %d, Height = %d, Depth = %d", 3, 4, 5); b. System.out.println("Width = %d, Height = %d, Depth = %d", 3, 4, 5); c. System.out.printf("Width = %s, Height = %s, Depth = %s", "3", "4", "5"); d. System.out.println("Width = " + 3 + ", Height = " + 4 + ", Depth = " + 5); e. System.out.println("Width = 3, Height = 4, Depth = 5");

The println should be replaced with printf System.out.println("Width = %d, Height = %d, Depth = %d", 3, 4, 5);

If an object consumes 20 bytes including the pointer, how many additional bytes are consumed by a cloned object? 16 1 4 8 20

The two objects are at different memory spaces. 20 is answer

Which one is incorrect for Student(String n) and setName(String n) available in class Student? One of them is a constructor. A Student object can be instantiated by using the keyword "new". Both can accept a String parameter. setName can be called by using a Student object. n is a class not an object.

The variable n is an object of String not a class answer is n is a class not an object.

What is the output of this program? for (int i = 0; i < 3; i++) { int sum = 0; for (int j = 0; j < 3; j++) { sum += j; } // end inner for } // end outer for System.out.println(sum); 0 Runtime error 3 Compile error 9

The variable sum cannot be declared in the "for" loop and accessed outside the "for" loop. It is not recognized. Compile error is answer

For these two programs, how many different class names can be found in total? public class Student{ public String name; public Student( ){ } public Student(String n){ name = n; } public void setName(String n){ name = n; } public String getName( ){ return name; } } _________________________________________________________________________________ public class MyProg{ public static void main(String[ ] args){ Student s1 = new Student( ); s1.name = "Mary"; Student s2 = new Student("John"); Student s3 = new Student( ); s3.setName("Brian"); System.out.println(s1.getName( )); System.out.println(s2.name); System.out.println(s3.getName( )); } } _________________________________________________________________________________ a. 3 b. 6 c. 4 d. 2 e. 5

There are Student, String, MyProg, and System. answer is 4

Which one is correct? switch(k) { case 1: break; case 2: default: System.out.println("Hello World"); break; } k = 0 does nothing. Regardless of k's value, "Hello World" is printed. k = 3 does nothing. k = 1 does nothing. k = 2 does nothing.

When k is equal to 1, it does nothing because of the keyword "break". For other values, the "Hello World" is printed. k = 1 does nothing. is answer

Given this program, how many System.out.println statements can be printed? public class C1 { int i1 = 100; static int i2 = 100; public C1( ) { } public static void main(String[] args){ C1 c1 = new C1( ); System.out.println(c1.i1); System.out.println(c1.i2); System.out.println(i1); System.out.println(i2); System.out.println(C1.i1); System.out.println(C1.i2); } } a. 4 b. 5 c. 2 d. 6

c1.i1, c1.i2, i2, and C1.i2 are ok. 4 is answer

Which one is correct? public class MainProg{ int i = 5; public static void main(String[] args){ int i = 10; MainProg mp = new MainProg(); System.out.println(i); System.out.println(mp.i); } } The first print statement shows 5. Instance variable i is re-defined in the main method. Both print statements show 5. The two statements show 10 and 5, respectively. The second print statement shows 10.

mp.i is corresponding to the instance variable, while i is a local variable. The two statements show 10 and 5, respectively. is answer


Conjuntos de estudio relacionados

Medication Administration Review Questions

View Set

Utilizing Sources in Social Studies

View Set

Chapter 17: Immunologic Disorders

View Set

Chapter 9 BA370 - Segmenting, Targeting and Positioning

View Set

Ch.12.1 Sound Byte: Network Typology and Navigation Devices_sc

View Set