Given the code fragment:
What is the result?
A.
10 : 10
B.
5 : 5
C.
5 : 10
D.
Compilation fails
10 : 10
Given the code fragment:
Which modification enables the code to print 54321?
A.
Replace line 6 with System, out. print (--x) ;
B.
At line 7, insert x --;
C.
Replace line 6 with --x; and, at line 7, insert system, out. print (x);
D.
Replace line 12 With return (x > 0) ? false: true;
At line 7, insert x --;
Which statement best describes encapsulation?
Which statement best describes encapsulation?
A.
. Encapsulation ensures that classes can be designed so that only certain fields and
methods of an object are accessible from other objects.
B.
Encapsulation ensures that classes can be designed so that their methods are
inheritable.
C.
Encapsulation ensures that classes can be designed with some fields and methods
declared as abstract.
t method.
D.
Encapsulation ensures that classes can be designed so that if a method has an
argument MyType x, any subclass of MyType can be passed to tha
. Encapsulation ensures that classes can be designed so that only certain fields and
methods of an object are accessible from other objects.
Given:
public class Test {
public static void main(String[] args) {
try {
String[] arr =new String[4];
arr[1] = "Unix";
arr[2] = "Linux";
arr[3] = "Solarios";
for (String var : arr) {
System.out.print(var + " ");
}
} catch(Exception e) {
System.out.print (e.getClass());
}
}
}
What is the result?
A.
A. Unix Linux Solaris
B.
BNull Unix Linux Solaris
C.
Class java.lang.Exception
D.
Class java.lang.NullPointerException
BNull Unix Linux Solaris
null Unix Linux Solarios
The first element, arr[0], has not been defined
Given:
What would be the output, if it is executed as a program?
A.
name =, pass =
B.
name = null, pass = null
C.
name = null, pass = false
D.
name = null pass = true
E.
Compile error.
name = null, pass = false
Both name and pass variables are instance variables, and we haven't given them any
values, so they take their default values. For Boolean default value is false and for string
which is not a primitive type default is null So at line 7, null will printed as the value of the
variable name, and at line 8 false will be printed. Hence Option C is correct.
As explained above options A, B and D are incorrect.
Code compiles fine so option E is incorrect.
Reference:
https://docs.oracle.com/javaseAutorial/java/javaOOAariables.html
Given:
What is the result?
A.
10:20
B.
0:20
C.
Compilation fails at line n1
D.
Compilation fails at line n2
Compilation fails at line n2
Given the following array:
A.
Option A
B.
Option B
C.
Option C
D.
Option D
E.
Option E
F.
Option F
Option B
Option E
All the remaining options have syntax errors
Given the code fragment:
What is the result?
A.
A B C
B.
A B C D E
C.
A B D E
D.
Compilation fails.
A B D E
Which of the following can fill in the blank in this code to make it compile? (Select 2 option)
.)
A.
On line 1, fill in throws
B.
On line 1, fill in throws new
C.
On line 2, fill in throw new
D.
On line 2, fill in throws
E.
On line 2, fill in throws new
On line 1, fill in throws
On line 2, fill in throw new
Option A and C are the correct answer.
In a method declaration, the keyword throws is used. So here at line 1 we have to use
option A.
To actually throw an exception, the keyword throw is used and a new exception is created,
so at line 2 we have to use throw and new keywords, which is option C. Finally it will look
like;
public void method() throws Exception {
throw new Exception0;
}
REFERENCE : httpsy/docs.oracle.com/javase/tutorial/essential/io/fileOps.html#exception
The correct answer is: On line 1, fill in throws. On line 2, fill in throw new
Which statement is true about Java byte code?
A.
. It can run on any platform.
B.
It can run on any platform only if it was compiled for that platform.
C.
It can run on any platform that has the Java Runtime Environment.
D.
It can run on any platform that has a Java compiler.
E.
It can run on any platform only if that platform has both the Java Runtime Environment
and a Java compiler.
It can run on any platform that has the Java Runtime Environment.
Given:
public class Test {
public static void main(String[] args) {
int day = 1;
switch (day) {
case "7": System.out.print("Uranus");
case "6": System.out.print("Saturn");
case "1": System.out.print("Mercury");
case "2": System.out.print("Venus");
case "3": System.out.print("Earth");
case "4": System.out.print("Mars");
case "5": System.out.print("Jupiter");
}
}
}
Which two modifications, made independently, enable the code to compile and run?
A.
Adding a break statement after each print statement
B.
Adding a default section within the switch code-block
C.
Changing the string literals in each case label to integer
D.
Changing the type of the variable day to String
E.
Arranging the case labels in ascending order
Adding a break statement after each print statement
Changing the string literals in each case label to integer
The following will work fine:
public class Test {
public static void main(String[] args) {
int day = 1;
switch (day) {
case 7: System.out.print("Uranus"); break;
case 6: System.out.print("Saturn"); break;
case 1: System.out.print("Mercury"); break;
case 2: System.out.print("Venus"); break;
case 3: System.out.print("Earth"); break;
case 4: System.out.print("Mars"); break;
case 5: System.out.print("Jupiter"); break;
}
}
}
Given:
class Sports {
int num_players;
String name, ground_condition;
Sports(int np, String sname, String sground){
num_players = np;
name = sname;
ground_condition = sground;
}
}
class Cricket extends Sports {
int num_umpires;
int num_substitutes;
Which code fragment can be inserted at line //insert code here to enable the code to
compile?
A.
Cricket() {
super(11, "Cricket", "Condidtion OK");
num_umpires =3;
num_substitutes=2;
}
B.
Cricket() {
super.ground_condition = "Condition OK";
super.name="Cricket";
super.num_players = 11;
num_umpires =3;
num_substitutes=2;
}
C.
Cricket() {
this(3,2);
super(11, "Cricket", "Condidtion OK");
}
Cricket(int nu, ns) {
this.num_umpires =nu;
this.num_substitutes=ns;
}
D.
Cricket() {
this.num_umpires =3;
this.num_substitutes=2;
super(11, "Cricket", "Condidtion OK");
}
Cricket() {
super(11, "Cricket", "Condidtion OK");
num_umpires =3;
num_substitutes=2;
}
Incorrect:
not C, not D: call to super must be the first statement in constructor.
Page 5 out of 20 Pages |
Previous |