25 Questions | By AARATHI_123 | Last updated: Mar 19, 2022 | Total Attempts: 626
Feedback
During the Quiz End of Quiz
Difficulty
Sequential Easy First Hard First
Basics of Java
1.
Import myLibrary.*; public class ShowSomeClass { // code for the class... } What is the name of the java file containing this program?
A.
MyLibrary.java
B.
ShowSomeClass.java
C.
ShowSomeClass
D.
ShowSomeClass.class
2.
Which of the following is TRUE?
A.
In java, an instance field declared public generates a compilation error
B.
Int is the name of a class available in the package java.lang
C.
Instance variable names may only contain letters and digits.
D.
A class has always a constructor (possibly automatically supplied by the java compiler)
3.
String river = new String(“Columbia”); System.out.println(river.length());
A.
6
B.
Columbia
C.
8
D.
River
4.
Which of the following may be part of a class definition?
A.
Instance variables
B.
Instance methods
C.
Constructors
D.
All of the above
5.
What is different between a Java applet and a Java application?
A.
An application can in general be trusted whereas an applet can't
B.
An applet must be executed in a browser environment.
C.
An applet is not able to access the files of the computer it runs on
D.
(A), (B) and (C).
6.
Public class MyClass{ public MyClass(){/*code*/} // more code... } To instantiate MyClass, you would write?
A.
MyClass mc = new MyClass();
B.
MyClass mc = MyClass();
C.
MyClass mc = MyClass;
D.
It can't be done. The constructor of MyClass should be defined as public void MyClass(){/*code*/}
7.
What is byte code in the context of Java?
A.
The type of code generated by a Java compiler
B.
The type of code generated by a Java Virtual Machine
C.
It is the code written within the instance methods of a class.
D.
It is another name for comments written within a program.
8.
What is garbage collection in the context of Java?
A.
The operating system periodically deletes all of the java files available on the system
B.
Any package imported in a program and not used is automatically deleted
C.
When all references to an object are gone, the memory used by the object is automatically reclaimed.
D.
. The JVM checks the output of any Java program and deletes anything that doesn't make sense.
9.
You read the following statement in a Java program that compiles and executes. submarine.dive(depth); What can you say for sure?
A.
Depth must be an int
B.
Dive must be a method
C.
Dive must be the name of an instance field.
D.
Submarine must be the name of a class
10.
Which will legally declare, construct, and initialize an array?
A.
Int [] myList = {"1", "2", "3"};
B.
Int [] myList = (5, 8, 2);
C.
Int myList [] [] = {4,9,7,0};
D.
Int myList [] = {4, 3, 7};
11.
Which is a reserved word in the Java programming language?
A.
Method
B.
Native
C.
Subclass
D.
Reference
12.
Which is a valid keyword in java?
A.
Interface
B.
String
C.
Float
D.
Unsigned
13.
public interface Foo { int k = 4; /* Line 3 */ } Which three piece of codes are equivalent to line 3?
A.
Final int k = 4;
B.
Public int k = 4;
C.
Static int k = 4;
D.
Abstract int k = 4;
E.
Volatile int k = 4;
14.
Which one is a valid declaration of a boolean?
A.
Boolean b1 = 0;
B.
Boolean b2 = 'false';
-
C.
Boolean b3 = false;
D.
Boolean b4 = Boolean.false();
15.
What will be the output of the program? public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( "Finally" ); } } }
A.
Finally
B.
Compilation fails.
C.
The code runs with no output.
D.
An exception is thrown at runtime.
16.
What will be the output of the program? try { int x = 0; int y = 5 / x; } catch (Exception e) { System.out.println("Exception"); } catch (ArithmeticException ae) { System.out.println(" Arithmetic Exception"); } System.out.println("finished");
A.
Finished
B.
Exception
C.
Compilation fails.
D.
Arithmetic Exception
17.
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 "); } } }
A.
Nothing. The program will not compile because no exceptions are specified.
B.
Nothing. The program will not compile because no catch clauses are specified.
C.
Hello world.
D.
Hello world Finally executing
18.
What will be the output of the program? class Equals { public static void main(String [] args) { int x = 100; double y = 100.1; boolean b = (x = y); /* Line 7 */ System.out.println(b); } }
A.
True
B.
False
C.
Compilation fails
D.
An exception is thrown at runtime
19.
Which class does not override the equals() and hashcode() methods, inheriting them directly from class Object?
A.
Java.lang.String
B.
Java.lang.Double
C.
Java.lang.StringBuffer
D.
Java.lang.Character
20.
You need to store elements in a collection that guarantees that no duplicates are stored. Which one of the following interfaces provide that capability?
A.
Java.util.Map
B.
Java.util.List
C.
Java.util.Collection
D.
None of the above
21.
What is the name of the method used to start a thread execution?
A.
Init();
B.
Start();
C.
Run();
D.
Resume();
22.
Which two are valid constructors for Thread?
A.
Thread(Runnable r, String name)
B.
Thread()
C.
Thread(int priority)
D.
Thread(Runnable r, ThreadGroup g)
23.
Which cannot directly cause a thread to stop executing?
A.
Calling the SetPriority() method on a Thread object.
B.
Calling the wait() method on an object.
C.
Calling notify() method on an object.
D.
Calling read() method on an InputStream object.
24.
Which of the following will directly stop the execution of a Thread?
A.
Wait()
B.
Notify()
C.
Notifyall()
D.
Exits synchronized code
25.
Which two of the following methods are defined in class Thread?
A.
Start()
B.
Notify()
C.
Run()
D.
Terminate()
This is the ultimate Java test for all those Java developer-wannabes who have just began practicing the programming language. It consists of over 93 questions of basically Core Java. So, if you are one of them and want to
have a...
Questions: 93 | Attempts: 21807 | Last updated: Mar 22, 2022
Sample Question
Object-Oriented Programming means ...Being objective about what you develop
Designing the application based on the objects discovered when analysing the problem
Writing an algorithm before writing your program and having a test plan
Writing a program composed of Java classes
Questions: 10 | Attempts: 14306 | Last updated: Mar 21, 2022
Sample Question
How will you describe Java?Programming Language
Platform
Both Programming Language and Platform
Abstract Machine
It is created for Beginners in Java.
This is to test the knowledge of any Java Developer wannabe.
Questions: 59 | Attempts: 6806 | Last updated: Mar 21, 2022
Sample Question
If none of the private/protected/public is specified for a member, that member ...Is accessible publicly
Is only accessible by other classes of the same package
Is only accessible from within the class
Is accessible by the class and its subclasses
More Java Quizzes
- Array Quizzes
- DotNET Quizzes
- Python Programming Quizzes
- Training Quizzes
- Visual Basic Quizzes