0% found this document useful (0 votes)
7 views22 pages

Java Programming Concepts Quiz

The document consists of a series of true or false questions, code snippets, and programming concepts related to Java. It covers topics such as exception handling, loops, arrays, classes, and method overloading. The questions aim to assess understanding of Java programming principles and syntax.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views22 pages

Java Programming Concepts Quiz

The document consists of a series of true or false questions, code snippets, and programming concepts related to Java. It covers topics such as exception handling, loops, arrays, classes, and method overloading. The questions aim to assess understanding of Java programming principles and syntax.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. A workspace can have one or more projects stored.

True or
false? (True).
2. In a project, one of the classes must include a main method. True or false?
(False).
3. For each opening bracket { it is not necessary for there to be a closing bracket } for
that the program compiles without errors. True or false? (False).
4. Given the code below, which of the following invocations are valid?
String s = new String("abc");
([Link]() (*), [Link](2) (*), [Link]() (*), [Link]('a', 'A') (*))
5. Consider the following code snippet:

ArrayIndexOutofBoundsException is thrown. (*)


6. Declaring and instantiating a String is very similar to any other type of variable. Without
Embargo, once instantiated, are final and cannot be modified. True or false?
(True).
7. What is the result when the following segment of code is compiled and executed?
int x = 22, y = 10;
double p = [Link]((x + y) / 2);
[Link](p);
It shows 4.0 (*)
[Link] a declaration statement that contains a number like [Link] number;
(*)
9. Consider the following:
He is writing a class and using a global variable. Inside a method
You declare a local variable with the same name as the global variable.

This style of programming is bad because within the method the global variable will have
precedence over the local variable with the same name.

True or false? False


10. Given the following statement: int z=5, m=6;
What line of Java code appropriately casts one type to another without loss of
data? double x = (double) z / m; (*)
11. What is the result of the following lines of code?
int j=7,k=5,m=8,result; result=j-k%3*m; [Link](result); -9 (*)
12. When importing another package in a class, you must import the entire package as well as the classes.
of packages that will be invoked. True or false? False
13. When importing another package in a class, you should only import the classes of that package that you need.
They will invoke and not the whole package. True or false? False
14. Which of the following definitions corresponds to a driver class?
contains a main method and other static methods (*)
15. Which of these two diagrams below illustrates the general form of a program?
in Java?

Example B

16. What is the purpose of the Area and the Views in the Eclipse Editor?
To navigate an information hierarchy.

To modify elements.
17. What symbols are required for a compiler to ignore a comment? // (*)
18. Which of the following statements shows 12345?
I. [Link]( 123 * 100 + 45);
II. [Link]("123" + 45);
III. [Link]( 12 + "345"); All of the above
19. Which line of the Java code assigns the value of 5 raised to the power of 8 to 'a'?
double a=[Link](5,8); (*)
[Link] a declaration statement that contains a number like 2.541.
float number; (*)
[Link] the following code:

What is the value of the variable x? 2 (*)


22. Which of the following is not a legal name for a variable? 4geeks (*)
23. When importing another package in a class, you must import only the classes from the package that you
They will invoke and not the whole package. True or false? False
24. The following defines a keyword for import:
Provide the compiler information that identifies the external classes used
within the current class.
[Link] following defines a class keyword:
Precede the class name.
26. When importing another package in a class, you must import the entire package as well as the classes.
Of packages that will be invoked. True or false?
[Link] the following code, which of the following would be true?
String s1 = "yes";
String s2 = "yes";
String s3 = new String(s1); [Link](s2) [Link](s1)
[Link] the code
String s1 = "abcdef";
String s2 = "abcdef";
String s3 = new String(s1);
Which of the following would be equivalent to false? s3 == s1
29. The following program prints 'Not Equal': True or False?

[Link] following prints Yes on the screen. True or False?

[Link] una construcción if-else la condición a ser evaluada debe terminar con un punto y
coma. True or false?
32. The three logical operators in Java are: &&, ||, !
The six relational operators in Java are: >, <, ==, !=, <=, >=
34. How would you use the ternary operator to rewrite this if statement?
if (gender == "male")
Mr.
else
Ms. Ms.
35. In an if-else construction, the condition to be evaluated must be enclosed between
parentheses. True or false?
36. What will be printed if the following Java code is executed?
if ((5.1 > 4.3 && 6.2 < 8.4) && !(7.2 < 3.5 || 1.2 == 2.1 || 2.2 != 2.25))
[Link]("TRUE"); else
[Link]("FALSE"); False
[Link] statements work with all types of inputs, but are not limited to int.
char y String. True or false?
38. What is the significant difference between a while loop and a do-while loop?
A DO-WHILE loop will always execute the code at least once, even if the statement
the condition for the WHILE is never true. A WHILE loop only runs if the
The conditional statement is true.
39. One advantage of using a while loop over a for loop is that the while loop always
It has a counter. True or false?
In a for loop, the counter is automatically incremented after each iteration.
of loop. True or false?
41. In the code snippet below, the syntax for initializing the loop is
Correct. True or false?
public class ForLoop {
public static void main (String args[])
{
for ((int i=10) (i<20) (i++))
[Link]("i: " + i);
}
}
42. When the loop for condition statement is met, it exits the construction.
True or false?
43. The following syntax represents a valid initialization of a for loop counter.
True or false?
public class ForLoop {
public static void main (String args[])
{
for (int i=10; i <20; i++)
{[Link]("i: "+i); }
}
}
44. What is a loop? A set of logics that are executed repeatedly until
a certain condition is met.
45. Which of the following options indicates the correct function of the symbol?
(two equal signs) compares the location of non-primitive objects in memory.

== (two equal signs) compares the values of primitive types, such as int or char.
46. What do exceptions in Java indicate?
The code was not written to account for all possible conditions.
There was a mistake in the code
[Link] an exception has already been thrown, what will the interpreter read next in the program?
The point at which the program catches the exception.
48. Which of the following would be correct ways to handle an 'index' exception?
out of bounds?
Rewrite the code to avoid the exception by disallowing the use of an index that
is not found within the matrix.
Throw the exception and catch it. When catching it, change the index to the array index.
What comes closest to exceeding the limits.
49. What does the interpreter look for when an exception is thrown?
A catch statement in the code.
50. What is the result of the following segment of code if the arguments of the line of
command sound "apples oranges pears"? 3

51. Which of the following statements is a valid array declaration?


double[] marks;
float average[];
52. Which of the following declares and initializes a one-dimensional array that can hold 5 types
Reference object? Object array=new Object[5];
53. After the execution of the following statement, which of the following are
true? the number[2] is 0
54. The following creates a reference in memory called 'q' that can derive to eight.
different doubles through an index. double[] q = new double[8];
True or false?
55. Which of the following declares and initializes a two-dimensional array that can hold 6 types
Reference object? Object[][] array=new Object[2][3];
56. The following creates a reference in memory called 'k' that can derive to six.
Different integers through an index. True or false?
57. Which of the following declares a one-dimensional array called names of size 8
so that all entries can be Strings? String[] names=new String[8];
58. Which of the following declares a one-dimensional array called "score" (puntaje) of
Type of integer that can hold 9 values? int[] score=new int[9];
59. The following creates a reference in memory called 'z' that can derive to seven.
Doubles through an index. True or false?
double z[] = new double[7];
60. Consider creating a class Square that extends the Rectangle class.
(rectangle) shown below. Knowing that a square always has the same
width and length, which of the following is the best representation of a constructor for
the class Square?
Response:

61. Which of the following is the correct way to invoke the overridden method needOil()?
from the superclass Robot in the subclass SqueakyRobot? [Link]();
62. It is possible to extend an existing class in Java, such as the "Applet" class. True
Is it false?
A static 'final' variable can change at runtime. True or false?
[Link] class methods can be created within any Java class.
True or false?
65.A static variable is always public. True or false?
66. What is polymorphism? A property of a variable or reference to contain multiple
types of objects.
67. Identify the step or steps involved in creating a Triangles Applet that displays two
triangles. Extend the Applet class to inherit all methods, including 'paint'.
[Link] se sobrescribe el método toString() con el siguiente código, ¿cuál sería el resultado de
the impression?

The string returned by the method would be printed. It would appear on the console screen:
[0,18,215,64,11,42,]
69. What type or types would work in the case of a method with variable arguments?
Integers (números enteros), Strings (cadenas), y Booleans (booleanos)
Arrays (matrices)
Objects
70. What makes overloading work?
The Java Virtual Machine searches until it finds a match with
the name of the constructor and the type of argument.
71. Which of the following options specifies the accessibility to variables, methods, and classes?
Access Modifiers
72. Which of the following statements about the code below is
true?
Car car1 = new Car();
Car car2=new Car();
car2=car1;
The reference car2 corresponds to an exact copy of the Car object it refers to.
car1.
[Link] variable names can only contain letters and digits.
True or false?
74. Which of the following statements is true?
A class always has a constructor (possibly provided automatically by
the Java compiler).
75. What is the keyword "final" used for in a Java program?
Prevents extending a class and overriding methods
76. Is there a difference between overriding a method and overloading it?
Yes. Overriding takes place in the subclass and allows redefining an inherited method
from the superclass, while overloading occurs within a class and allows
to have multiple methods with the same name.
77. If it is possible to inherit from an abstract class, what must be done to prevent
does a compiler error occur?
Override all abstract methods of the main class.
78. The constructor method must always have at least one parameter. True or false?
79. A constructor must have the same name as the class in which it is declared. True
or false?
80. A class can have multiple constructors. True or false?
81. What could be a reason for needing to pass an object to a method?
All of the above
82. It is possible to have more than one constructor with the same name in a class, but their
Parameters must be different. True or false?
83. What type or types would work in the case of a method with variable arguments?
Integers (números enteros), Strings (cadenas), y Booleans (booleanos)
Arrays (matrices)
Objects
84. There is only one copy of a static class variable in the JVM. True or false?
[Link] methods can return any type of object. True or false?
86. Which of the following statements about static methods is true?
There is once per class
87. Which of the following is the most accurate description of the reuse philosophy?
code? Programming philosophy that promotes more efficient and simpler coding
through the use of the existing code for the new applications.
88. Which of the following is the correct way to create a Battlefield applet?
battle)? public class Battlefield extends Applet{...}
89. Where should the superclass constructor be invoked? In the first line of the
subclass constructor
90. Let’s suppose you are writing a program in which the user is asked to
indicate the coordinates where you believe the princess is located within the castle.
The program moves the prince to the coordinates specified by the user. If the
the princess is not located at those coordinates, a hint is given to the user to help them
to approach the princess. The user can indicate again where they think she is.
the princess.
If your program does not consider the possibility that the user enters coordinates outside
from the castle, where the princess could not be, what would happen if the user enters said
coordinates?; how could this situation be handled in your code?
An exception would occur. It could be handled by throwing the exception in your code in
in case the user enters invalid coordinates. When the exception is caught, the
the prince moves to the coordinates closest to those indicated by the user, within the
castle.
An exception would occur. It could be handled by throwing an exception in your code in
in case the user enters invalid coordinates. Once the exception is caught,
the user could be asked to enter coordinates that are within the range
corresponding to the castle.
91. Choose the best response to this statement: An error can be managed through its
launch and capture, just like an exception.
False. An error is much more serious than an exception and cannot be handled.
adequately in a program.
What does it mean to 'catch' or 'capture' an exception? It means to handle it.
93. Which of the following is the correct definition of 'exception'?
Problem that can be corrected or managed by the code.
A logic error occurs if a semicolon is unintentionally placed at the end of
the initialization of a loop because the interpreter reads it as the only line inside the loop,
a line that does nothing. It is interpreted that everything following the semicolon is code
outside the loop. True or false?
95. Which of the following statements is not a valid array declaration?
counter int[];
96. The following matrix declaration is valid. True or False?
int x[] = int[10];
[Link] of the following declares and initializes a one-dimensional array called values of
size 5 so that all entries contain 1?
int[] values={1,1,1,1,1};
98. Which of the following declares and initializes a one-dimensional array called "words"
size 10" so that all entries can be Strings?
String[] words=new String[10];
99. What is the result of the following code segment?
int array[][] = {{1,2,3},{3,2,1}};
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
[Link](2*array[1][1]); 444444
100. double array[] = new double[8]; After executing this statement, what
Which of the following is true?
101. The following matrix declaration is valid:
int[] y = new int[5]; True
102. What will be the content of a variable matrix table after executing the
next code?

100
010
001
103. Which of the following declares a one-dimensional array called scores of type
What integer number can hold 14 values? int[] scores=new int[14];
104. Which of the following statements is a valid array declaration?
float average[];
double[] marks;
105. What should replace the comment "//your answer here" (enter your answ
here) in the code below, if the code is designed not to take measures
when i % 2 is 0 (in other words when i is even)?

for(int i = 0; i < 10; i++){


if(i%2 == 0)
//your answer here
else
k += 3;
} continue();
106. Identify what situation would be an example of a while loop. All of the above.
107. Updating the entry of a loop allows you to implement the code with the following
element instead of always repeating the code with the same element. True or
false?
108. When the condition statement of the for loop is met, it exits the
Construction. True or false?
109. In the code snippet below, the syntax for initializing the loop
Is it correct? True or false?
public class ForLoop {
public static void main (String args[])
{
for ((int i=10) (i<20) (i++))
[Link]("i: " + i);
}
}
110. What is a loop?
A set of logics that run repeatedly until a certain condition
it is fulfilled.
111. What is the function of the word 'break' in Java?
112. Exit the current loop or case statement.
113. This keyword is used to instruct specific code when the
input for a switch statement does not match any of the cases.
Defaul();
114. The three logical operators in Java are: &&, ||, !
115. The following code snippet appropriately implements the statement
switch. True or false?
default(input)
switch '+' :
answer+=num;
break;
case '-' :
answer-=num;
break;
!default
Invalid input
116. Switch statements work with all types of input, but they are not limited to
an int, char and String. True or false?
117. Determine if this boolean expression evaluates to true or false:
!(3<4&&5>6||6<=6&&7-1==6)
118. How would you use the ternary operator to rewrite the if statement?
if (balance < 500)
fee = 10;
else
fee = 0; fee= ( balance < 500) ? 10 : 0;
119. Which of the following correctly unites the keyword of the switch statement
with its function?
case: indicate which code is executed if the user's input matches the element
specified
switch: identifica qué elemento se comparará con el elemento de las sentencias case para
find a possible match
default: indicates which code to execute if the input does not match any of the cases
120. How would you use the ternary operator to rewrite this if statement?
if (skillLevel > 5)
numberOfEnemies = 10;
else
numberOfEnemies = 5; numberOfEnemies = ( skillLevel > 5) ? 10 : 5;
121. When importing another package in a class, you must import the entire package like this
like the classes of packages that will be invoked. True or false?
122. The following defines a keyword of the class: Precede the name of the
class.
123. The following defines a keyword for import:
Provide the compiler information that identifies the external classes used
within the current class.
124. Which of the following definitions corresponds to a controller class
(driver)? it contains a main method and other static methods
125. What is printed through the following segment of code?

\\\\
126. The following program prints 'Not Equal': True or False?

127. Declaring and instantiating a String is very similar to any other type of variable.
However, once instantiated, they are final and cannot be modified. True or
false?
128. A workspace can have one or more stored projects.
True or false?
129. When Eclipse starts, the Welcome page is displayed. Once this
the page is closing cannot return to the resources available on this page. True or
false?
130. What symbols are required for a compiler to ignore a comment? //
131. What is the result of the following lines of code? 0
int j=6,k=4,m=12,result;
result=j/m*k;
[Link](result);
132. Which of the following examples is not a correct Java code? boolean b=1
133. Given the following statement: int z=5,m=6;
What line of Java code appropriately casts one type to another without loss of
data? double x=(double)z/m;
134. What is the result of the following lines of code?
int j=7,k=5,m=8,result; result=j-k%3*m; [Link](result); -9
135. Which line of code does not assign 3.5 to the variable x? 3.5=x;
136. The following code creates an object of type Horse:
Whale a = new Whale(); False
137. In which of the following cases is an object of the Car class created that appears in
continuation?
Car c = new Car(3000, 'Toyota');
138. In which of the following cases is a method created that returns a value?
boolean?

139. An access modifier is a keyword that allows subclasses


access the methods, data, and constructors corresponding to the main class.
True or false?
140. What is a hierarchy?
Structure that categorizes and organizes relationships between ideas and concepts of things
placing the more general ones at the top and the more specific ones at the bottom.
141. What is the correct definition of 'subclass' (or 'class')?
secondary" )?
Class that inherits methods and fields from a more general class.
142. You are tasked with writing a method that compares two objects of the type Career.
A requirement of your task is that the method compares the instance data.
"greatestPossibleSalary" (mayor salario posible) correspondiente a los objetos Career. El
tipo de datos del campo "greatestPossibleSalary" es int (número entero).
What would be the best return type for the compare method?
Career, because if it returns Career objects with a higher salary, it will be able to employ the same.
method later to compare other aspects of the Career objects.
143. Select the correct implementation of a public access modifier for the
divide method. public int divide(int a, int b) {return a/b;}
144. Static classes can have access specifiers other than
from the main class. True or false?
145. Any instance of the same class can assign a new value to a variable.
static. True or false?
146. Pueden asignárseles nuevos valores a las variables estáticas anteponiéndoles la
keyword "this" and a period. True or false?
147. Would this code be correct if Dog (dog) is a HousePet (pet)?
what yes or why not?
HousePet Scooby = new Dog(); Yes, because polymorphism allows it since Dog is
a subclass of HousePet.
148. If it is possible to inherit from an abstract class, what must be done to avoid it?
What happens if there is a compiler error?
Override all the abstract methods of the main class.
149. Which of these two diagrams below illustrates the general form of
a program in Java?

B
150. The following defines a keyword of the package:
Define where this class resides in relation to other classes and provide a level of
access control.
151. The following defines a keyword for import:
Provide the compiler information that identifies external classes
used within the current class.
152. From which menu can you return to the Eclipse Welcome Page by choosing
Welcome? Help
153. When converting gallons to liters, it is better to place the result of the calculation in
a variable with a data type _______________. Double
154. What is printed through the following segment of code?

\\\\\\\\\\\\\\
155. The == operator tests if two String references point to the same object.
Chain. True or false?
156. Which line of Java code will assign the value of the square root of 11 to a
variable called 'a'? double a=[Link](11);
157. What two values can a boolean variable have? True and false
158. Which of the following is the name of a primitive data type in Java?
int
159. Write a declarative sentence that contains a number like 2.541.
Float number
160. Which of the following statements are correct? float loan; double duty;
161. Which of the following correctly connects the keyword of the switch statement?
with its function?
162. Why are loops useful?
163. It is necessary to end all loops at some point in your Java program.
True or false?
164. Which of the following correctly links the keyword of the switch statement?
with its function?
switch: identify which element will be compared with the element of the case statements for
find a possible match
case: indicate which code runs if the user's input matches the element
specified
default: indicates which code to execute if the input does not match any of the cases
165. Suppose you misspell the name of a method when calling it in your program.
Which of the following options explains why an exception occurs?
I don't know, but an error occurs when the program is compiled.
166. What of the following may be a reason to throw an exception?
To eliminate exceptions that affect the functioning of the program.
167. What exception message indicates that a variable may have been written incorrectly in
any part of the program? variableName cannot be assigned to a variable
168. It is possible to throw and catch an exception within the catch block of a code.
True or false?
169. What are exceptions used for in Java?
To correct errors in the code and handle extraordinary cases.
170. Which of the following statements adds all the elements of the array?
one-dimensional and then it is printed on the screen?
int total
for(int i=1;i total+=prices[i];
[Link](total);
171. What is the result of the following code segment?
0
172. What is the result of the following segment of code if the line arguments
the command is 'a b c d e f g'?

e
173. What is the result of the following code segment?

777777
174. What is the result of the following code segment?

1286864
175. Which of the following declares and initializes a two-dimensional array?
int[][] array={{1,1,1},{1,1,1},{1,1,1}};
176. Which of the following statements prints each element of the prices of the
one-dimensional matrix on the screen?
for(int i=0; i < [Link]; i++){[Link](prices[i]);}
177. Which of the following declares a one-dimensional array called names of
size 8 so that all entries can be Strings?
String[] names=new String[8];
178. Why is it not possible to extend more than one class at a time in a hierarchy?
inheritance?
It is not necessary since all public content passes from the superclass to the
subclass, from the subclass to its own subclasses and so on.
179. In which of the following cases is an "is-a" relationship correctly described?
Useful term that serves to conceptualize the relationships that exist between the
nodes or leaves in a hierarchy of inheritance
180. Consider creating a Square class that extends the Rectangle class
(rectangle) shown below. Knowing that a square always has the same
width and length, which of the following is the best representation of a constructor for
the class Square? public class Rectangle extends Shape { private int length; private int
width; public Rectangle(String color, int length, int width) { super(color); [Link] = length;
[Link] = width; } }
public Square(String color, int size) { super(color, size, size); }
181. Static methods can modify instance variables at runtime.
execution. True or false?
182. A static inner class can be used to return an instance of its class.
external container. True or false?
183. Static methods cannot modify any class variable values in
runtime. True or false?
184. In which of the following cases is an instance of the class that appears created?
continuation?

ThisClass t=new ThisClass(5);


185. In which of the following cases is a method created that compiles without errors in the
class?

186. In which of the following cases is an object of the Car class created that appears to
continuation?

Car c = new Car(3000, "Toyota");


187. What is the most beneficial in this situation?
Joe is a university student who typically loses his books. Replacing them is costly for him.
more and more. With the idea of organizing, Joe wants to create a program that stores
his textbooks in a group of books, but he intends for each type of book to be the topic
del libro (es decir, MathBook [libro de matemáticas] is a book). ¿Cómo podría almacenar
the books of different subjects in a single matrix? Using polymorphism.
188. If a class is immutable, it must be abstract. True or false?
189. An abstract class cannot extend another abstract class. True or false?
190. Which of the following could be a reason to need to pass an object to a
method? All of the above
191. What segment of code represents the correct way to invoke a counter?
for the method with variable arguments, which takes integers as parameters
variable arguments? counter(1, 5, 8, 17, 11000005);
192. Which of the following are access modifiers?
protected (*) public (*) private (*) default (no access modifier)
193. What is the problem with this code?

No
handle the exception.
194. What is the result of the following code segment?

11
195. Which of the following declares a one-dimensional array called 'score'?
of integer type that can hold 9 values? int[] score=new int[9];
196. Which of the following is the correct definition of "overload"?
Existence of more than one constructor with the same name but different arguments.
197. Identify the error or errors presented in the following class. Select all that apply
corresponding. No method named min is defined.
No method called min is defined.
198. Which of the following is the correct definition of 'parameter'?
Variable de una declaración de método que se pasa al método.
199. If a superclass has a private variable, could it be accessed or modified?
a subclass? Why yes or why not?
No. A private variable can only be modified by the same class it belongs to.
declares, beyond their heritage.
200. If a class is inherited, the constructors of that class are not inherited. True
or false?
201. Why would a programmer use polymorphism instead of a standard array?
Because matrices only work with the same type of object, while the
polymorphism does not have this limitation.
202. Which of the following access modifiers does not work with a variable?
static? friendly
203. Static classes can exist as inner classes. True or false?
204. The following statement compiles and executes. What information is considered true?
[Link](numFeet); grows should be the name of a method.
205. The following code is a good example of how the reference this is used.
True or false?

False
206. In which of the following cases is a class named Diver created?
a constructor, and 2 instance variables, maxDepth (maximum depth) and certified
(certificate)?
207. What is the result of the following code segment if the arguments for
The command line is "a b c d e f"?

6
208. Which of the following statements is a valid array declaration?
float average[];
double[] marks;
209. The following segment of code prints all five command line arguments
Commands entered in this program. True or false?

210. Which of the following statements initializes a two-dimensional array with 3 rows and 2 columns?
columns? int[][] a={{1,1},{1,1},{1,1}};
211. The following creates a reference in memory called 'y' that can derive to
Five different integers through an index. True or false?
int[] y = new int[5];
212. Which of the following declares a one-dimensional array called names of
size 8 so that all entries can be Strings?
String[] names=new String[8];
213. Static class variables that are not 'final' must be private to avoid
that other classes modify them. True or false?
214. If Oak (oak) extends Tree (tree), it is possible to declare an object in such a way
what
Tree grandfatherT = new Oak(); True
215. What allows Java to correctly and automatically determine which method
invoke according to the type of object being referred to at the time of calling the method?
Dynamic link
216. Which of the following statements about an abstract class is true?
It is possible to create references of this type.
217. Identify the controller class that correctly initializes the employee Jane.
and Brandon. The Employee class is shown below.
public class Employee {
private String name;
private int age;
private double salary;
public Employee(String n, int a, double s) {
name = n;
age = a;
salary = s;
}
//the methods of this class would go here
}
public class driver_class {
public static void main(String[] args) {
Employee Jane = new Employee("Jane", 48, 35.00);
Employee Brandon = new Employee("Brandon", 36, 20.00);
}
}
218. What is the Java Applet?
Graphic or visual element included in Java. (*)
Web program in Java integrated into a web browser.
219. A subclass can be a superclass. True or false?
220. Which of the following can be a reason to return an object? All of them
previous
221. Following the guidelines of good programming, what access modifier
should be used for class fields in the following situation?
An automotive insurance company wants to create a class called Customer that
store all the data of a certain client, including the following fields:
vehicle data, policy data, and credit card number. Private
222. If a method throws an exception, where can that exception be caught?
You can catch it in the method that threw the exception or in any other method that
It has invoked the method that launched it.
223. The following array declaration is valid. True or false?
int k[] = new int[10];
224. What is the result of the following code segment?

666666
225. If Sandal (sandal) extends Shoe (shoe), it is possible to declare an object of
in such a way that
Sandal s = new Shoe(); True
226. In which of the following cases is the use of the word correctly described?
key 'super'? Keyword that allows subclasses to access the methods,
data and constructors corresponding to the main class.
227. Why are hierarchies useful for inheritance?
They are used to organize the relationship between a superclass and its respective subclasses.
228. Static classes can extend the main class. True or false?
229. Static classes can be created as independent classes. True or false?
230. In which of the following cases is the calculate method correctly invoked?
ThisClass t=new ThisClass(); int x=[Link](3,4);
231. Which of the following statements is true?
A class always has a constructor (possibly provided automatically by
the Java compiler.
232. The following segment of code initializes a two-dimensional array of data types
Primitives. True or false?
double[][] a=new double[4][5];
233. What line of code shows the correct way to throw an exception?
throw new Exception("Array index is out of bounds");
234. In which of the following cases would an exception occur for 'index out of bounds'?
matrix (array) limits?
Refer to an element of an array that is located at an index greater than the length.
from the matrix minus one.
235. The following segment of code initializes a two-dimensional array of references.
True or false?
String[][] array={{"a", "b", "C"},{"a", "b", "c"}};
236. What is the result of the following code segment?

777777
237. What is the result of the following code segment?
int num[]={9,8,7,6,5,4,3,2,1};
for(int i=0;i<9;i=i+3)
[Link](num[i]); 963
238. What is the result of the following code segment?

7531
239. In which of the following cases is the correct UML representation shown?
superclass Planet and its subclass Earth?
240. Generally, methods are declared as 'public' so that they can be used.
other classes. True or false?
241. Static methods can read instance variables. True or false?
242. Consider the following method of the Test class:

public static List returnList(List list)


{
return list;
}

Which of the following program segments of the Test client class will not present
compilation errors? I and III
243. What is the definition of 'method with variable arguments'?
Type of argument that allows invoking the same method with a different number of arguments.
244. It is possible to overload a method that is not a constructor. True or false?
245. What is the output of the following code segment:

int n = 13;
[Link](doNothing(n));
[Link](" ", n);

where the code of the doNothing method is:


public double doNothing(int n)
{
n = n + 8;
return (double) 12/n;
}? 0.571, 13
246. Given:
public class MyClass{ public MyClass(){/*code*/} // more code...} What would I write to
instantiate MyClass? MyClass m = new MyClass();

You might also like