Core Java online Test

1)Which will legally declare, construct, and initialize an array?


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


3.Which is a valid declaration within an interface?


4.Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class?


5.Which two cause a compiler error?

1.float[ ] f = new float(3);

2.float f2[ ] = new float[ ];

3.float[ ]f1 = new float[3];

4.float f3[ ] = new float[3];

5.float f5[ ] = {1.0f, 2.0f, 2.0f};


6.Which one creates an instance of an array?


7.class A

{

protected int method1(int a, int b)

{

return 0;

}

}

Which is valid in a class that extends class A?


8.What is the narrowest valid returnType for methodA in line 3?

public class ReturnIt

{

returnType methodA(byte x, double y) /* Line 3 */

{

return (long)x / y * 2;

}

}


9.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?


10.Which three are valid method signatures in an interface?

1.private int getArea();

2.public float getVol(float x);

3.public void main(String [] args);

4.public static void main(String [] args);

5.boolean setFlag(Boolean [] test);


11.Which cause a compiler error?


12.Which of the following is/are legal method declarations?

1.protected abstract void m1();

2.static final void m1(){}

3.synchronized public final void m1() {}

4.private native void m1();


13.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?


14.interface Base

{

boolean m1 ();

byte m2(short s);

}

which two code fragments will compile?

1.interface Base2 implements Base {}

abstract class Class2 extends Base

{ public boolean m1(){ return true; }}

3.abstract class Class2 implements Base {}

4.abstract class Class2 implements Base

{ public boolean m1(){ return (7 > 4); }}

5.abstract class Class2 implements Base

{ protected boolean m1(){ return (5 > 7) }}


15.interface Base

{

boolean m1 ();

byte m2(short s);

}

which two code fragments will compile?

1.interface Base2 implements Base {}

abstract class Class2 extends Base

{ public boolean m1(){ return true; }}

3.abstract class Class2 implements Base {}

4.abstract class Class2 implements Base

{ public boolean m1(){ return (7 > 4); }}

5.abstract class Class2 implements Base

{ protected boolean m1(){ return (5 > 7) }}


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


17.Which of the following are Java reserved words?

1.run

2.import

3.default

4.implements


18.What is the numerical range of char?


19.Which interface provides the capability to store objects using a key-value pair?


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


21.What will be the output of the program?

public class MyProgram

{

public static void main(String args[])

{

try

{

System.out.print("Hello world ");

}

finally

{

System.out.println("Finally executing ");

}

}

}


22.What will be the output of the program?

public class MyProgram

{

public static void main(String args[])

{

try

{

System.out.print("Hello world ");

}

finally

{

System.out.println("Finally executing ");

}

}

}


23.What will be the output of the program?

public class Foo

{

public static void main(String[] args)

{

try

{

return;

}

finally

{

System.out.println( "Finally" );

}

}

}


24.public class While

{

public void loop()

{

int x= 0;

while ( 1 ) /* Line 6 */

{

System.out.print("x plus one is " + (x + 1)); /* Line 8 */

}

}

}

Which statement is true?


25.public void test(int x)

{

int odd = 1;

if(odd) /* Line 4 */

{

System.out.println("odd");

}

else

{

System.out.println("even");

}

}

Which statement is true?


26.switch(x)

{

default:

System.out.println("Hello");

}

Which two are acceptable types for x?

1.byte

2.long

3.char

4.float

5.Short

6.Long


27.class Hexy {

public static void main(String[] args) {

Integer i = 42;

String s = (i<40)?"life":(i>50)?"universe":"everything";

System.out.println(s);

}

}

What is the result?


28.public class Frodo extends Hobbit {

public static void main(String[] args) {

Short myGold = 7;

System.out.println(countGold(myGold, 6));

}

}

class Hobbit {

int countGold(int x, int y) { return x + y; }

}

What is the result?


29.Given the following piece of code:

class Person { public int number; }

public class Test{

public void doIt(int i , Person p){

i = 5;

p.number = 8;

}

public static void main(String args[]){

int x = 0;

Person p = new Person();

new Test().doIt(x, p);

System.out.println(x + " " + p.number);

}

}


30.Given these classes:

public class Person{

public void talk(){ System.out.print("I am a Person "); }

}

public class Student extends Person {

public void talk(){ System.out.print("I am a Student "); }

}

what is the result of this piece of code:

public class Test{

public static void main(String args[]){

Person p = new Student();

p.talk();

}

}


31.Given the following piece of code:

public interface Guard{

void doYourJob();

}

abstract public class Dog implements Guard{}

which of the following statements is correct?


32.Given the following piece of code:

public class Company{

public abstract double calculateSalaries();

}

which of the following statements is true?


33.Suppose a class has public visibility. In this class we define a protected method. Which of the

following statements is correct?


34.Given the following piece of code:

public class Test {

public static void main(String args[]) {

int i = 0, j = 5 ;

for( ; (i < 3) && (j++ < 10) ; i++ ) {

System.out.print(" " + i + " " + j );

}

System.out.print(" " + i + " " + j );

}

}


35.Which of the following statements about arrays is syntactically wrong?


36._______ literals are enclosed in single quotes.


37._______variables are the local variables that are accessed by the function in which the variables are declared.


38.Consider the statements:

Statement A: The name of a variable can begin with a digit.

Statement B: The name of a variable can contain white spaces.

Identify the correct option.


39.What is the default value of the float data type?


40.Predict the output of the expression, 16 % 3?


41.What is the type of inheritance in which a subclass is derived from more than one super class known as?


42.Identify the feature of OOPS that means ignoring the non-essential details of an object and concentrating on its essential features?


43.______ is the feature of OOPS that implies that the non-essential details of an object are hidden from the user and an access is provided to its essential details.


44.Which language is a Object Oriented Programming language?


45.What is the acronym for OOP?


46.What is the value of "d" after this line of code has been executed?

double d = Math.round ( 2.5 + Math.random( ));


47.Which of the following would compile without error?


48.Which of the following are valid calls to Math.max?

1. Math.max(1,4)

2. Math.max(2.3, 5)

3. Math.max(1, 3, 5, 7)

4. Math.max(-1.5, -2.8f)


49.Which four options describe the correct default values for array elements of the

types indicated?

1. int -> 0

2. String -> "null"

3. Dog -> null

4. char -> '\u0000'

5. float -> 0.0f

6. boolean -> true


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


51.Which is a reserved word in the Java programming language?


52.Which is a valid keyword in java?


53.Which three are legal array declarations?

1. int [] myScores [];

2. char [] myChars;

3. int [6] myScores;

4. Dog myDogs [];

5. Dog myDogs [7];


54.Which one of the following will declare an array and initialize it with five numbers?


55.Which three are valid declarations of a char?

1. char c1 = 064770;

2. char c2 = 'face';

3. char c3 = 0xbeef;

4. char c4 = \u0022;

5. char c5 = '\iface';

6. char c6 = '\uface';


56.Which is the valid declarations within an interface definition?


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


58.Which two of the following methods are defined in class Thread?

1. start()

2. wait()

3. notify()

4. run()

5. terminate()


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


60.Which will contain the body of the thread?


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


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


63.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?


64.Which interface does java.util.HashTable implement?


65.Which interface provides the capability to store objects using a key-value pair?


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


67.Which is true about an anonymous inner class?


68.Which is true about a method-local inner class?


69.Which statement is true about a static nested class?


70.Consider the following program:

import myLibrary.*;

public class ShowSomeClass

{

// code for the class...

}

What is the name of the java file containing this program?


71.Which of the following is TRUE?


72.Consider the following code snippet

String river = new String(“Columbia”);

System.out.println(river.length());

What is printed?


73.A constructor


74.Which of the following may be part of a class definition?


75.What is different between a Java applet and a Java application?


76.Consider

public class MyClass{

public MyClass(){/*code*/}

// more code...

}

To instantiate MyClass, you would write?


77.What is byte code in the context of Java?


78.What is garbage collection in the context of Java?


79.You read the following statement in a Java program that compiles and

executes.

submarine.dive(depth);

What can you say for sure?


80. public class While

{

public void loop()

{

int x= 0;

while ( 1 ) /* Line 6 */

{

System.out.print("x plus one is " + (x + 1)); /* Line 8 */

}

}

}

Which statement is true?



































































































































































































































































































































































































































































































































































Description:

"Java language" redirects here. For the natural language from the Indonesian island of Java, see Javanese language.
Not to be confused with JavaScript.
Java
Paradigm(s) multi-paradigm: object-oriented, structured, imperative, generic, reflective
Appeared in 1995 (1995)[1]
Designed by James Gosling and
Sun Microsystems
Developer Oracle Corporation
Stable release Java Standard Edition 7 Update 7 (1.7.07) (August 30, 2012; 47 days ago (2012-08-30))
Typing discipline Static, strong, safe, nominative, manifest
Major implementations OpenJDK, many others
Dialects Generic Java, Pizza
Influenced by Ada 83, C++, C#,[2] Eiffel,[3] Generic Java, Mesa,[4] Modula-3,[5] Oberon,[6] Objective-C,[7] UCSD Pascal,[8][9] Smalltalk
Influenced Ada 2005, BeanShell, C#, Clojure, D, ECMAScript, Groovy, J#, JavaScript, PHP, Python, Scala, Seed7, Vala
OS Cross-platform (multi-platform) object-oriented programming language
License GNU General Public License, Java Community Process
Usual filename extensions .java, .class, .jar
Website For Java Developers
Java Programming at Wikibooks

Java is a programming language originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities than either C or C++. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java is as of 2012 one of the most popular programming languages in use, particularly for client-server web applications, with a reported 10 million users.[10][11]

The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1991 and first released in 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java and GNU Classpath.

Discussion

Your Facebook Friends on WizIQ