Pregunta 1
Pregunta
what are the valid components of a java source file (choose all that apply)
Respuesta
-
package statement
-
import statements
-
methods
-
variables
-
java compiler
-
java runtime environment
Pregunta 2
Pregunta
the following munbered list of java class components is not in any particular order. select the correct order of their occurrence in a java class (choose all that apply):
1. comments
2. import statements
3. package statement
4. methods
5. class declaration
6. variables.
Respuesta
-
1,3,2,5,6,4
-
3,1,2,5,4,6
-
3,2,1,4,5,6
-
3,2,1,5,6,4
Pregunta 3
Pregunta
which of the following examples define the correct java class structure
Pregunta 4
Pregunta
given the following definition of the class EjavaGuru,
what is the output of the previous class, if it is executed using the command:
"java EjavaGuru one two three four"
Respuesta
-
one:two:three
-
EJavaGuru:one:tow
-
java:EJavaGuru:one
-
tow:three:four
Pregunta 5
Pregunta
given the following contents of the java source code file MyClass.java select the correct options
Respuesta
-
the imported class, java.util.Date, can be accessed only in the class Student.
-
the imported class, java.util.Date, can be accessed by both the Student and Course classes
-
Both of the classes Student and Course are defined in the package com.ejavaguru.
-
Course is defined in the default java package.
Pregunta 6
Pregunta
which of the following options, when inserted at //INSERT CODE HERE will print out EJavaGuru
Respuesta
-
public void main (String [] args)
-
public void main (String args [] )
-
static public void main (String[] array)
-
public static void main (String args)
-
static public main (String args[])
Pregunta 7
Pregunta
select the correct options
Respuesta
-
you can start the execution of a java application through the main method
-
the java compiler calls and executes the main method
-
the java virtual machine calls and executes the main method
-
a class calls and executes the main method
Pregunta 8
Pregunta
A class Course is definided in a package com.ejavaguru. Given that the physical location of the corresponding class file is /mycode/com/ejavaguru/Course.class and execution takes place within the mycode directory, which of the following lines of code, when inserted //INSERT CODE HERE, will import the Course class into the class MyCourse
Respuesta
-
import mycode.com.ejavaguru.Course;
-
import com.ejavaguru.Course;
-
import mycode.com.ejavaguru;
-
import com.ejavaguru;
-
import mycode.com.ejavaguru.*;
-
import com.ejavaguru.*;
Pregunta 9
Pregunta
examine the following code:
which of the following statements will be true if the variable courseName is defined as a private variable?
Respuesta
-
class EJavaGuru will print Java
-
class EJavaGuru will print null
-
class EJavaGuru will won't compile
-
class EJavaGuru will throw an exception at runtime
Pregunta 10
Pregunta
Given the following definition of the class Course:
what's the output of the following code?
Respuesta
-
the class EJavaGuru will print java
-
the class EJavaGuru will print null
-
the class EJavaGuru will not compile
-
the class EJavaGuru will throw an exception at runtime
Pregunta 11
Pregunta
Given the following code, select the correct options
Respuesta
-
you can't define a method argument as a private variable
-
a method argument should be defined with either public or default accessibility
-
for overridden methods, method arguments should be defined with protected accessibility.
-
none of the above
Pregunta 12
Pregunta
Select all incorrect statements
Respuesta
-
a programmer can't define a new primitive data type
-
a programmer can define a new primitive data type
-
once assigned, the value of a primitive can't be modified
-
a value can't be assigned to a primitive variable
Pregunta 13
Pregunta
which of the options are correct for the following code?
Respuesta
-
code at line 4 fails to compile
-
code at line 5 fails to compile
-
code at line 6 fails to compile
-
code at line 7 fails to compile
Pregunta 14
Pregunta
what is the output of the following code?
Pregunta 15
Pregunta
Select the options that is / are the best choice for de following
Respuesta
-
long, boolean, double
-
long, int, float
-
char, int, double
-
long, boolean, float
Pregunta 16
Pregunta
which of the following options contain correct code to declare and initialize variables to store numbers?
Respuesta
-
bit a = 0;
-
integer a2 = 7;
-
long a3 =0X10C;
-
short a4 = 0512;
-
double a5 = 10;
-
byte a7 = -0;
-
long a8 = 123456789;
Pregunta 17
Pregunta
Select the options that, when inserted at //INSERTE CODE HERE, will make the following code output code a value of 11
Respuesta
-
ctr +=1;
-
ctr =+1;
-
++ctr;
-
ctr = 1;
Pregunta 18
Pregunta
what is the output of the following code
Respuesta
-
218
-
232
-
246
-
compilation error
Pregunta 19
Pregunta
what is true about the following lines of code
Respuesta
-
code prints true
-
code prints false
-
code prints >= false
-
compilation error
Pregunta 20
Pregunta
which of the following methods correctly accepts three whole numbers as methods arguments and returns their sum as a decimal number?
Pregunta 21
Pregunta
how can you include encapsulation in your class design
Respuesta
-
define instance variables as private members
-
define public methods to access and modify the instance variables
-
define some of the instance variables as public members
-
all of the previous
Pregunta 22
Pregunta
if the functionality of the operators = and > were to be swapped in java (for the code on line number 4, 5, and 6), what would be the result of the following code?
Respuesta
-
true, true, false
-
10.0, false, false
-
false, false, false
-
compilation error
Pregunta 23
Pregunta
examine the following code and select the correct options
Pregunta 24
Pregunta
examine the following code and select the correct options
Respuesta
-
the heigth de a Person can never be set to more than 300.
-
the previous code is an example of a well-encapsulated class
-
the class would be better encapsulated if the heigth validation weren't set to 300.
-
even though the class isn't well encapsulated, it can be inherited by other classes
Pregunta 25
Pregunta
which of the following correctly accepts three whole numbers as method arguments and returns their sum as a decimal number?
Pregunta 26
Pregunta
which of the following statements are true?
Respuesta
-
if the return type of a method is int, the method can return a value od type byte
-
a method may or may not return a value
-
if the return type of a method is void, it can define a return statement without a value, as follows: "return;"
-
a method may or may not accept any method arguments.
-
a method should accept at least one method argument or define its return type.
-
a method whose return type is String can't return null
Pregunta 27
Pregunta
Given the following definition of class Person,
Respuesta
-
anotherMethod, anotherMethod, someMethod, someMethod
-
anotherMethod, EJava, someMethod, someMethod
-
anotherMethod, EJava, someMethod, EJava
-
Compilation error.
Pregunta 28
Pregunta
what is the ouput of the following code?
Respuesta
-
20
10
11
11
-
20
20
11
10
-
20
10
11
10
-
compilation error
Pregunta 29
Pregunta
Given the following signature of method eJava, choose the options that correctly overload this method
Respuesta
-
private String eJava(int val, String firstName, double dur)
-
public void eJava(int val1, String val2, double val3)
-
String eJava(int name , String age, double duration)
-
float eJava(double name, String age, byte duration)
-
ArrayList<String> eJava()
-
char[] eJava(double numbers)
-
String eJava()
Pregunta 30
Pregunta
given the following code,
Respuesta
-
Compilation error
-
Rintime exception
-
int
String
-
long
Object
Pregunta 31
Pregunta
examine the following code and select the correct options:
Respuesta
-
The class EJava defines three overloaded contructors
-
The class Ejava define two overloaded contructors. The private constructor isn't counted as an overloaded constructor.
-
Constructors with different access modifiers can't call each other
-
the code prints the following:
protected
private
public
-
the code prints the following:
public
private
protected
Pregunta 32
Pregunta
Select the incorrect options
Respuesta
-
If a user defines a private constructor for a public class, Java creates a public default constructor for the class.
-
A class that gets a default constructor doesn’t have overloaded constructors.
-
A user can overload the default constructor of a class.
-
The following class is eligible for default constructor:
class EJava {}
-
The following class is also eligible for a default constructor:
class EJava {
void EJava() {}
}
Pregunta 33
Pregunta
What is the output of the following code?
Respuesta
-
4c010
-
4c10
-
113
-
103
-
Compilation error
Pregunta 34
Pregunta
What is the output of the following code?
Respuesta
-
0:0
-
a:b
-
0:b
-
a:0
-
compilation error
Pregunta 35
Pregunta
Which of the following are valid lines of code to define a multidimensional
int array?
Respuesta
-
int[][] array1 = {{1, 2, 3}, {}, {1, 2,3, 4, 5}};
-
int[][] array2 = new array() {{1, 2, 3}, {}, {1, 2,3, 4, 5}};
-
int[][] array3 = {1, 2, 3}, {0}, {1, 2,3, 4, 5};
-
int[][] array5 = new int[2][];
Pregunta 36
Pregunta
Which of the following statements are correct?
Respuesta
-
By default, an ArrayList creates an array with an initial size of 16 to store its elements.
-
Because ArrayList stores only objects, you can’t pass element of an ArrayList to a switch construct.
-
Calling clear() or remove() on an ArrayList, will remove all its elements.
-
If you frequently add elements to an ArrayList, specifying a larger capacity will improve the code efficiency.
-
Calling the method clone() on an ArrayList creates its shallow copy; that is, it doesn’t clone the individual list elements.
Pregunta 37
Pregunta
Which of the following statements are correct?
Respuesta
-
An ArrayList offers a resizable array, which is easily managed using the methods it provides. You can add and remove elements from an ArrayList.
-
Values stored by an ArrayList can be modified.
-
You can iterate through elements of an ArrayList using a for loop, Iterator, or ListIterator.
-
An ArrayList requires you to specify the total elements before you can store any elements in it.
-
An ArrayList can store any type of object.
Pregunta 38
Pregunta
What is the output of the following code?
Respuesta
-
Line 7 prints true
-
Line 7 prints false
-
Line 8 prints -1
-
Line 8 prints 1
-
Line 9 removes all elements of the list ejg
-
Line 9 sets ejg to null
-
Line 10 prints null
-
Line 10 prints []
-
Line 10 prints a value similar to ArrayList@16356
-
Line 11 throws an exception
Pregunta 39
Pregunta
What is the output of the following code?
Pregunta 40
Pregunta
What is the output of the following code?
Respuesta
-
gZmeAZ
-
gZmeAa
-
gZm
-
gZ
-
game
Pregunta 41
Pregunta
What is the output of the following code?
Respuesta
-
gZmeAZ
-
gZmeAa
-
gZm
-
gZ
-
game
Pregunta 42
Pregunta
What is the output of the following code?
Respuesta
-
12S512S5
-
12S12S
-
1025102S
-
dRuntime exception
Pregunta 43
Pregunta
What is the output of the following code?
Respuesta
-
521
-
Runtime exception
-
65321
-
65431
Pregunta 44
Pregunta
What’s the output of the following code?
Pregunta 45
Pregunta
What’s the output of the following code?
Pregunta 46
Pregunta
Which of the following statements is true?
Respuesta
-
The enhanced for loop can’t be used within a regular for loop.
-
The enhanced for loop can’t be used within a while loop.
-
The enhanced for loop can be used within a do-while loop.
-
The enhanced for loop can’t be used within a switch construct.
-
All of the above statements are false.
Pregunta 47
Pregunta
What’s the output of the following code?
Respuesta
-
true
false
ABC
-
false
ABC
-
true
ABC
-
Compilation error
Pregunta 48
Pregunta
Given the following code, which of the following lines of code can individually replace the //INSERT CODE HERE line so that the code compiles successfully?
Respuesta
-
case 10*3: System.out.println(2);
-
case num: System.out.println(3);
-
case 10/3: System.out.println(4);
-
case num2: System.out.println(5);
Pregunta 49
Pregunta
What’s the output of the following code?
Respuesta
-
default
-
default
4
-
4
-
Compilation error
Pregunta 50
Pregunta
What’s the output of the following code?
Respuesta
-
default
case1
case2
-
case1
case2
-
case2
-
Compilation error
-
Runtime exception
Pregunta 51
Pregunta
What’s the output of the following code?
Pregunta 52
Pregunta
What’s the output of the following code?
Respuesta
-
else
-
0
1
2
-
0
1
-
Compilation error
Pregunta 53
Pregunta
What’s the output of the following code?
Respuesta
-
Compilation error
-
0
5
-
0
5
10
-
10
-
0
1
5
-
5