Given:
What is the result?
A.
2 4 6 8 10 12
B.
2 4 6 8 10 12 14
C.
Compilation fails
D.
he program prints multiple of 2 infinite times
E.
The program prints nothing
2 4 6 8 10 12 14
Given the code fragment:
Which two modifications, made independently, enable the code to compile?
A.
A. Make the method at line n1 public.
B.
Make the method at line n2 public.
C.
Make the method at line n3 public.
D.
Make the method at line n3 protected.
E.
Make the method at line n4 public.
Make the method at line n3 public.
Make the method at line n3 protected.
Given:
What is the output?
A.
[21, 13, 11]
B.
[30]
C.
[]
D.
Compilation fails due to error at line 7
E.
Compilation tails due to error at line 10
Compilation fails due to error at line 7
Option D is the correct answer.
Code fails to compile as we can't use primitive for collections type, so in this code trying to
use int at line 7, causes a compile error. We should have use wrapper. Integer there. So
option D is correct.
https://docs.oracle.eom/javase/8/docs/api/java/util/ArrayList.html
public class Student {
public String name = "";
public int age = 0;
public String major = "Undeclared";
public boolean fulltime = true;
public void display() {
System.out.println("Name: " + name + " Major: " + major); }
public boolean isFullTime() {
return fulltime;
}
}
Which line of code initializes a student instance?
A.
Student student1;
B.
Student student1 = Student.new();
C.
Student student1 = new Student();
D.
Student student1 = Student();
Student student1 = new Student();
Given:
class Base {
public static void main(String[] args) {
System.out.println("Base " + args[2]);
}
}
public class Sub extends Base{
public static void main(String[] args) {
System.out.println("Overriden " + args[1]);
}
}
And the commands:
javac Sub.java
java Sub 10 20 30
What is the result?
A.
Base 30
B.
Overridden 20
C.
Overridden 20
Base 30
D.
Base 30
Overridden 20
Overridden 20
Which statement is true about the default constructor of a top-level class?
A.
It can take arguments.
B.
It has private access modifier in its declaration.
C.
It can be overloaded.
D.
The default constructor of a subclass always invokes the no-argument constructor of its
superclass.
The default constructor of a subclass always invokes the no-argument constructor of its
superclass.
In both Java and C#, a "default constructor" refers to a nullary constructor
that is automatically generated by the compiler if no constructors have been defined for the
class. The default constructor is also empty, meaning that it does nothing. A programmer
defined constructor that takes no parameters is also called a default constructor
Given the code fragment from three files:
Which code fragment, when inserted at line 2, enables the code to compile?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
E.
Option E
Option E
Given:
class MarksOutOfBoundsException extends IndexOutOfBoundsException { }
public class GradingProcess {
void verify(int marks) throws IndexOutOfBoundsException {
if (marks > 100) {
throw new MarksOutOfBoundsException();
}
if (marks > 50) {
System.out.print("Pass");
} else {
System.out.print("Fail");
}
}
public static void main(String[] args) {
int marks = Integer.parseInt(args[2]);
try {
new GradingProcess().verify(marks));
} catch(Exception e) {
System.out.print(e.getClass());
}
}
}
And the command line invocation:
Java grading process 89 50 104
What is the result?
A.
Pass
B.
Fail
C.
Class MarketOutOfBoundsException
D.
Class IndexOutOfBoundsException
E.
Class Exception
Class MarketOutOfBoundsException
The value 104 will cause a MarketOutOfBoundsException
Given the code fragment:
Which statement is true?
A.
After line 8, three objects are eligible for garbage collection
B.
After line 8, two objects are eligible for garbage collection
C.
After line 8, one object is eligible for garbage collection
D.
After line 8, none of the objects are eligible for garbage collection
After line 8, one object is eligible for garbage collection
Given the following classes:
Which two options fail to compile when placed at line n1 of the main method?
A.
employee.salary = 50_000;
B.
director.salary = 80_000;
C.
employee.budget = 200_000;
D.
manager.budget = 1_000_000;
E.
manager.stockOption = 500;
F.
director.stockOptions = 1_000;
employee.budget = 200_000;
manager.stockOption = 500;
Given:
Which option enables the code to compile?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
Option C
Option D
Given:
public class MyClass {
public static void main(String[] args) {
String s = " Java Duke ";
int len = s.trim().length();
System.out.print(len);
}
}
What is the result?
A.
8
B.
9
C.
11
D.
10
E.
Compilation fails
9
Java - String trim() Method
This method returns a copy of the string, with leading and trailing whitespace omitted
Page 7 out of 20 Pages |
Previous |