Java
Java
Java
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
Observe the code
int x = 6;
p.display(x);
void display(int x) {
a.
An exception is thrown at runtime.
b.
display x = 6 main x = 6
c.
display x = 7 main x = 7
d.
display x = 6 main x = 7
e.
display x = 7 main x = 6
f.
Compilation fails.
Feedback
Your answer is correct.
The correct answer is:
display x = 6 main x = 6
Question 2
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
Predict the output.
class X
void display(int a)
System.out.println("INT");
void display(double d)
System.out.println("DOUBLE");
new X().display(100);
Select one:
a.
DOUBLE
b.
Compilation Fails
c.
Ambiguity error
d.
INT
Feedback
Your answer is correct.
The correct answer is: INT
Question 3
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
Integer x1 = new Integer(120);
int x2 = 120;
System.out.println( x1 == x2 );
Select one:
a.
CastException
b.
Runtime Exception
c.
Compilation Error
d.
true
e.
false
Feedback
Your answer is correct.
The correct answer is: true
Question 4
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
Which of the following is not a Java modifier?
Select one:
a.
public
b.
private
c.
virtual
d.
protected
Feedback
Your answer is correct.
The correct answer is: virtual
Question 5
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
The methods of a class with the ____________ access specifier cannot be accessed in
its subclass class of different package.
Select one:
a.
public
b.
protected
c.
default
Feedback
Your answer is correct.
We call the access specifier default as “package level access” because, in a clss,
members declared as default can be accessed only within the package in which it is
declared.
4. }
1. package p2;
6. }
7. }
Select one:
a.
p1.Test.display(names);
b.
p1.display(names);
c.
TestMain cannot use methods in p1
d.
import p1.Test.*; display(names);
e.
display(names);
Feedback
Your answer is correct.
The correct answer is: p1.Test.display(names);
Question 7
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
What is the outcome of the code?
return description;
this.description = description;
item=new Item();
item.setDescription(desc);
it.setDescription("Gobstopper");
it2.setDescription("Fizzylifting");
it.modifyDesc(it,"Scrumdiddlyumptious");
System.out.println(it.getDescription());
System.out.println(it2.getDescription());
}
Select one:
a.
Scrumdiddlyumptious
b.
Gobstopper
Scrumdiddlyumptious
c.
Gobstopper
Fizzylifting
d.
Scrumdiddlyumptious
Fizzylifting
e.
Compilation fails
Feedback
Your answer is correct.
The correct answer is: Gobstopper
Fizzylifting
Question 8
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
Given:
String msg;
int noOfWords;
public Message() {
this.noOfWords = noOfWords;
msg = "Welcome";
Message();
System.out.println(m.msg);
}
What will be the output ?
Select one:
a.
Welcome
b.
The code runs with no output
c.
Welcome Thank you 5
d.
Compilation fails
e.
Welcome Thank you
f.
An exception is thrown at runtime
Feedback
Your answer is correct.
The correct answer is: Compilation fails
-----------------------------------------------------------------------------------
--------------------------------------------------------------
Question 1
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
package edu.ABC.model;
a.
import static edu.ABC.model.Account.*;
return INTEREST_RATE;
b.
import static edu.ABC.model.Account ;
return INTEREST_RATE;
c.
package edu.ABC.model;
return INTEREST_RATE;
d.
import edu.ABC.model.Account ;
return Account.INTEREST_RATE;
Feedback
Your answer is correct.
The correct answers are:
import static edu.ABC.model.Account.*;
public class Loan {
public double getInterest() {
return INTEREST_RATE;
}
}, import edu.ABC.model.Account ;
public class Loan {
public double getInterest() {
return Account.INTEREST_RATE;
}
}
Question 2
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
Predict the Output of following Java Program.
class Test {
int x = 10;
System.out.println(x);
Select one:
a.
0
b.
Compile Time Error
c.
Runtime Exception
d.
10
Feedback
Your answer is correct.
The correct answer is: Compile Time Error
Question 3
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
Identify the true statement(s).
Statement 2 : The default constructor will implicitly invoke the default / no-
argument constructor of the super class
Select one:
a.
1, 2 and 4
b.
1 and 2
c.
1, 2 and 3
d.
2 and 3
Feedback
Your answer is correct.
The correct answer is: 1 and 2
Question 4
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
A JavaBeans component has the following field:
Which two pairs of method declarations follow the JavaBeans standard for accessing
this field? (Choose two.)
a.
public void setEnabled( boolean enabled )
b.
public void setEnabled( boolean enabled )
c.
public boolean setEnabled( boolean enabled )
d.
public void setEnabled( boolean enabled )
Feedback
Your answer is correct.
When writing getters and setters, setters return type is void and getters return
type is the corresponding data type. Naming convention is camelcase notation. For
setters start with set followed by field name and for getters start with get
followed by field name. For boolean return type, it should start with 'is' or
'are' followed by field name.
The correct answers are: public void setEnabled( boolean enabled )
public boolean isEnabled(), public void setEnabled( boolean enabled )
public boolean getEnabled()
Question 5
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
What does this() mean in constructor chaining concept?
Select one:
a.
Used for calling the current object of the parent class.
b.
Used for calling the current object of the same class.
c.
Used for calling the parameterized constructor of the parent class.
d.
Used for calling the no argument constructor of the same class.
Feedback
Your answer is correct.
The correct answer is: Used for calling the no argument constructor of the same
class.
Question 6
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
Identify which statement is true about construtors.
Select one:
a.
Constructor will be invoked explicitly like other methods
b.
Constructor should have same name as class name, but not case sensitive
c.
Constructor of a class should not have a return type, which means the return type
is void
d.
Constructor can be overloaded
Feedback
Your answer is correct.
The correct answer is:
Constructor can be overloaded
Question 7
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
Given:
public class ItemTest
{
private final int id;
public ItemTest(int id) {
this.id = id;
}
public void updateId(int newId) {
id = newId;
}
public static void main(String[] args) {
ItemTest fa = new ItemTest(42);
fa.updateId(69);
System.out.println(fa.id);
}
}
What is the result?
Select one:
a.
69
b.
Runtime Error
c.
CompileTime Error
Feedback
Your answer is correct.
The correct answer is: CompileTime Error
Question 8
Correct
Mark 1.00 out of 1.00
Not flaggedFlag question
Question text
Which members of a class can be accessed by other classes is determined by the
________________
Select one:
a.
Access specifier
b.
class
c.
variables
d.
constructor
Feedback
Your answer is correct.
The correct answer is: Access specifier