Friday, 1 September 2017

Java Questions

Download JAVA Questions




Which one of these lists contains only Java programming language keywords?   


class, if, void, long, Int, continue   
goto, instanceof, native, finally, default, throws   
try, virtual, throw, final, volatile, transient   
strictfp, constant, super, implements, do   


2


```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which will legally declare, construct, and initialize an array?   


int [] myList = {1, 2, 3};   
int [] myList = (5, 8, 2);   
int myList [] [] = {4,9,7,0};   
int myList [] = {4, 3, 7};   


4


```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which is a reserved word in the Java programming language?   


method   
native   
subclasses   
reference   


2


``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which is a valid keyword in java?   


interface   
string   
Float   
unsigned   


1


````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which is true about an anonymous inner class?   


It can extend exactly one class and implement exactly one interface   
It can extend exactly one class and can implement multiple interfaces.   
It can extend exactly one class or implement exactly one interface.   
It can implement multiple interfaces regardless of whether it also extends a class.   


3


`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which is true about a method-local inner class?   


It must be marked final.   
It can be marked abstract.   
It can be marked public.   
It can be marked static.   


2


``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which statement is true about a static nested class?   


You must have a reference to an instance of the enclosing class in order to instantiate it.   
It does not have access to nonstatic members of the enclosing class.   
It's variables and methods must be static.   
It must extend the enclosing class.   


2


``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which constructs an anonymous inner class instance?   


Runnable r = new Runnable() { };   
Runnable r = new Runnable(public void run() { });
Runnable r = new Runnable { public void run(){}}   
System.out.println(new Runnable() {public void run() { }});   


4


``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?   


public   
private   
protected   
transient   


3


``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````


What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?   


public   
abstract   
protected   
default access   


4


`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````


Which cause a compiler error?   


int[ ] scores = {3, 5, 7};   
int [ ][ ] scores = {2,7,6}, {9,3,45};   
String cats[ ] = {Fluffy, Spot, Zeus};   
boolean results[ ] = new boolean [] {true, false, true};   


2


````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?   


public   
private   
protected   
default access   


4


`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which one creates an instance of an array?   


int[ ] ia = new int[15];   
float fa = new float[20];   
char[ ] ca = Some String;   
int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };   


1


```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````


Which of the following class level (nonlocal) variable declarations will not compile?   


protected int a;   
transient int b = 3;   
private synchronized int e;   
volatile int d;   


3


`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````


What is the name of the method used to start a thread execution?   


init();   
start();   
run();   
resume();   


2


`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````


Which cannot directly cause a thread to stop executing?   


Calling the SetPriority() method on a Thread object.
Calling notify() method on an object.   
Calling the wait() method on an object.   
Calling read() method on an InputStream object.   


2


```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````


Which of the following will directly stop the execution of a Thread?   


wait();   
start();   
stop();   
main();   


1


```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which method registers a thread in a thread scheduler?   


run();   
construct();   
start();   
register();   


3


`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which of the following will not directly cause a thread to stop?   


notify()   
wait()   
InputStream access   
sleep()   


1


``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````


Which class or interface defines the wait(), notify(),and notifyAll() methods?   


Object   
Thread   
Runnable   
Class   


1


````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````


Which of the following would compile without error?   


int a = Math.abs(-5);   
int b = Math.abs(5.0);   
int c = Math.abs(5.5F);   
int d = Math.abs(5L);   


1


````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````


Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance?   


TreeMap   
HashMap   
LinkedHashMap   
The answer depends on the implementation of the existing instance.


3


```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?   


java.lang.String   
java.lang.Double   
java.lang.StringBuffer   
java.lang.Character   


3


``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?   


java.util.HashSet   
java.util.LinkedHashSet   
java.util.List   
java.util.ArrayList   


4


```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````


You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?   


java.util.Map   
java.util.Set   
java.util.List   
java.util.Collection   


2





No comments:

Post a Comment

Code

<html> <head> <title>Implimentation</title> <script type="text/javascript"> fu...