Given a class named Book, which one of these is a valid constructor declaration for the class?
Anonymous Quiz
35%
Book(Book b) { }
24%
Book Book() { }
12%
private final Book() { }
29%
void Book() { }
0%
abstract Book() { }
public class MyClass {
long var;
public void MyClass(long param) { var = param; } //(1) public static void main(String[] args) { MyClass a,b; a = new MyClass(); //(2) b = new MyClass(5); //(3) } }
long var;
public void MyClass(long param) { var = param; } //(1) public static void main(String[] args) { MyClass a,b; a = new MyClass(); //(2) b = new MyClass(5); //(3) } }
Anonymous Quiz
0%
A compilation ERROR will occur at (1), since constructors cannot specify a return value
29%
A compilation error will occur at (2), since the class does not have a default constructor
57%
compilation error(3)since the class does not have a constructor which takes one argument of type int
7%
The program will compile correctly
7%
The program will compile and execute correctly.
Given the following class, which of these is valid way of referring to the class from outside of the package net.basemaster?
package net.basemaster;
public class Base { // . . . } Select the correct answer
package net.basemaster;
public class Base { // . . . } Select the correct answer
Anonymous Quiz
18%
By simply referring to the class as Base
12%
By simply referring to the class as basemaster.Base
53%
By simply referring to the class as net.basemaster.Base
0%
By simply referring to the class as net.Base
18%
By importing with net.* and referring to the class as basemaster.Base.
Which one of the following class definitions is a valid definition of a class that cannot be instantiated?
Anonymous Quiz
24%
class Ghost { abstract void haunt(); }
29%
abstract class Ghost { void haunt(); }
35%
abstract class Ghost { void haunt() { }; }
6%
abstract Ghost { abstract void haunt(); }
6%
static class Ghost { abstract haunt(); }
Which one of the following class definitions is a valid definition of a class that cannot be extended?
Anonymous Quiz
0%
class Link { }
11%
abstract class Link { }
21%
native class Link { }
16%
static class Link { }
53%
final class Link { }
Given the following definition of a class, which fields are accessible from outside the package
com.corporation.project?
package com.corporation.project; public class MyClass { int i; public int j; protected int k; private int l; }
com.corporation.project?
package com.corporation.project; public class MyClass { int i; public int j; protected int k; private int l; }
Anonymous Quiz
6%
Field i is accessible in all classes in other packages
38%
Field j is accessible in all classes in other packages
25%
Field k is accessible in all classes in other packages
13%
Field l is accessible in all classes in other packages
19%
Field l is accessible in subclasses only in other packages
How restrictive is the default accessibility compared to public, protected, and private accessibility?
Anonymous Quiz
13%
Less restrictive than public
47%
More restrictive than public, but less restrictive than protected
33%
More restrictive than protected, but less restrictive than private
7%
More restrictive than private
Which statement is true about accessibility of members?
Anonymous Quiz
36%
Private members are always accessible from within the same package
36%
Private members can only be accessed by code from within the class of the member
14%
member with default accessibility can be accessed by any subclass of the class in which it is define
7%
Private members cannot be accessed at all
7%
Package/default accessibility for a member can be declared using the keyword default.
Which of the following is true about the use of modifiers?
(a)
If no accessibility modifier (public, protected, and private) is specified for a member declaration, the member is only accessible for classes in the package of its class and subclasses of its class anywhere
(b)
You cannot specify accessibility of local variables. They are only accessible within the block in which they are declared
(c)
Subclasses of a class must reside in the same package as the class they extend
(d)
Local variables can be declared static
(e)
None of the above.
(a)
If no accessibility modifier (public, protected, and private) is specified for a member declaration, the member is only accessible for classes in the package of its class and subclasses of its class anywhere
(b)
You cannot specify accessibility of local variables. They are only accessible within the block in which they are declared
(c)
Subclasses of a class must reside in the same package as the class they extend
(d)
Local variables can be declared static
(e)
None of the above.
public class Program
{
public static void main(String[] args) {
try{
int[] a={1,2,3,4};
for(int i=1;i<=4;i++){
System.out.println("a["+i+"]="+a[i]+"\n");
}
}
catch(Exception e){
System.out.println("error="+e);
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("ArrayIndexOutOfBoundsException");
}
}
}
A)Compile Time Error
B) Runtime Error
C) Error Code is printed
D) Array is printed
{
public static void main(String[] args) {
try{
int[] a={1,2,3,4};
for(int i=1;i<=4;i++){
System.out.println("a["+i+"]="+a[i]+"\n");
}
}
catch(Exception e){
System.out.println("error="+e);
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("ArrayIndexOutOfBoundsException");
}
}
}
A)Compile Time Error
B) Runtime Error
C) Error Code is printed
D) Array is printed
Options
Anonymous Quiz
28%
Compile time error
22%
Runtime Error
22%
Error Code is printed
28%
Array is printed
In Iterator, hasMoreElements() method of Enumeration has been changed to:
Anonymous Quiz
16%
hasNextElement()
11%
isNext()
63%
hasNext()
11%
name remains same
TreeSet internally uses that one to store elements?
Anonymous Quiz
27%
HashMap
23%
LinkedHashMap
50%
TreeMap
An attempt to add the null key to a TreeSet will result in:
Anonymous Quiz
16%
Will compile
53%
Compile time Exception
11%
Error
21%
Runtime - NullPointerException
TreeSet maintains which order?
Anonymous Quiz
57%
Ascending Order
19%
Descending Order
24%
None of the above
Enumeration returned by ArrayList is
Anonymous Quiz
43%
Fail-fast
48%
Fail-safe
10%
None of the above
How are you able to sort given HashMap on basis of values
Anonymous Quiz
21%
Implement Comparator interface and override its compare method
14%
It is not possible
57%
Implement Comparator interface and override its compareTo method
7%
Implement Comparator and Comparable interface
The Comparator interface contains the method?
Anonymous Quiz
27%
compareWith()
45%
compareTo()
27%
compare()