OCJP Mock JGI - III tests understanding of Java multithreading, exception handling, and object synchronization. It evaluates skills in handling runtime exceptions and thread operations in Java, essential for Java certification aspirants.
It is possible for more than two threads to deadlock at once.
The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state.
Deadlocked threads release once their sleep() method's sleep duration has expired.
Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are used incorrectly.
It is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly.
If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of Thread.yield().
Rate this question:
This code can throw an InterruptedException.
This code can throw an IllegalMonitorStateException.
This code can throw a TimeoutException after ten minutes.
Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally.
A call to notify() or notifyAll() from another thread might cause this method to complete normally.
This code does NOT compile unless "obj.wait()" is replaced with "((Thread) obj).wait()".
Rate this question:
The output could be 5-1 6-1 6-2 5-2
The output could be 6-1 6-2 5-1 5-2
The output could be 6-1 5-2 6-2 5-1
The output could be 6-1 6-2 5-1 7-1
Rate this question:
Compilation fails.
An exception is thrown at runtime.
The code executes normally and prints "foo".
The code executes normally, but nothing is printed.
Rate this question:
Public class Circle implements Shape { private int radius; }
Public abstract class Circle extends Shape { private int radius; }
Public class Circle extends Shape { private int radius; public void draw(); }
Public abstract class Circle implements Shape { private int radius; public void draw(); }
Public class Circle extends Shape { private int radius; public void draw() {/* code here */}
Public abstract class Circle implements Shape { private int radius; public void draw() { /* code here */ }
Rate this question:
Hi hi
Hi world
World world
Compilation fails.
An exception is thrown at runtime.
Rate this question:
Direction d = NORTH;
Nav.Direction d = NORTH;
Direction d = Direction.NORTH;
Nav.Direction d = Nav.Direction.NORTH;
Rate this question:
MyColor skyColor = BLUE;
MyColor treeColor = MyColor.GREEN;
If(RED.getRGB() < BLUE.getRGB()) { }
Compilation fails due to other error(s) in the code.
MyColor purple = new MyColor(0xff00ff);
MyColor purple = MyColor.BLUE + MyColor.RED;
Rate this question:
0
1
2
3
4
5
Rate this question:
Compilation fails.
Atom granite
Granite granite
Atom granite granite
An exception is thrown at runtime.
Atom granite atom granite
Rate this question:
Test
Null
An exception is thrown at runtime.
Compilation fails because of an error in line 1.
Compilation fails because of an error in line 4.
Compilation fails because of an error in line 5.
Rate this question:
0.0
Compilation fails.
A ParseException is thrown by the parse method at runtime.
A NumberFormatException is thrown by the parse method at runtime.
Rate this question:
Public int blipvert(int x) { return 0; }
Private int blipvert(int x) { return 0; }
Private int blipvert(long x) { return 0; }
Protected long blipvert(int x) { return 0; }
Protected int blipvert(long x) { return 0; }
Protected long blipvert(long x) { return 0; }
Protected long blipvert(int x, int y) { return 0; }
Rate this question:
Change line 2 to: public int a;
Change line 2 to: protected int a;
Change line 13 to: public Sub() { this(5); }
Change line 13 to: public Sub() { super(5); }
Change line 13 to: public Sub() { super(a); }
Rate this question:
Class Man extends Dog { }
Class Man implements Dog { }
Class Man { private BestFriend dog; }
Class Man { private Dog bestFriend; }
Class Man { private Dog; }
Class Man { private BestFriend; }
Rate this question:
Any class
Only the Target class
Any class in the test package
Any class that extends Target
Rate this question:
0, 0, 0
150, 60, 0
Compilation fails.
150, 150, 150
An exception is thrown at runtime.
Rate this question:
If line 10 is removed, the compilation succeeds.
If line 11 is removed, the compilation succeeds.
If line 12 is removed, the compilation succeeds.
If line 13 is removed, the compilation succeeds.
More than one line must be removed for compilation to succeed.
Rate this question:
Looser coupling
Tighter coupling
Lower cohesion
Higher cohesion
Weaker encapsulation
Stronger encapsulation
Rate this question:
Canada
Null Canada
Canada null
Canada Canada
Compilation fails due to an error on line 26.
Compilation fails due to an error on line 29.
Rate this question:
Restore 400
Restore 403
Restore 453
Compilation fails.
An exception is thrown at runtime.
Rate this question:
18. d = df.parse(ds);
18. d = df.getDate(ds);
18. try { 19. d = df.parse(ds); 20. } catch(ParseException e) { };
18. try { 19. d = df.getDate(ds); 20. } catch(ParseException e) { };
Rate this question:
B = nf.parse( input );
B = nf.format( input );
B = nf.equals( input );
B = nf.parseObject( input );
Rate this question:
42
420
462
42042
Compilation fails.
An exception is thrown at runtime.
Rate this question:
Closing an open stream.
Flushing an open stream.
Writing to an open stream.
Writing a line separator to an open stream.
Rate this question:
Compilation fails.
The file system has a new empty directory named dir.
The file system has a new empty directory named newDir.
The file system has a directory named dir, containing a file f1.txt.
The file system has a directory named newDir, containing a file f1.txt.
Rate this question:
Sb1.append("abc"); s1.append("abc");
Sb1.append("abc"); s1.concat("abc");
Sb1.concat("abc"); s1.append("abc");
Sb1.concat("abc"); s1.concat("abc");
Sb1.append("abc"); s1 = s1.concat("abc");
Sb1.concat("abc"); s1 = s1.concat("abc");
Sb1.append("abc"); s1 = s1 + s1.concat("abc");
Sb1.concat("abc"); s1 = s1 + s1.concat("abc");
Rate this question:
System.out.printf("|%7d| \n", d);
System.out.printf("|%7f| \n", d);
System.out.printf("|%3.7d| \n", d);
System.out.printf("|%3.7f| \n", d);
System.out.printf("|%7.3d| \n", d);
System.out.printf("|%7.3f| \n", d);
Rate this question:
2
3
1 2
2 3
1 2 3
Compilation fails.
An exception is thrown at runtime.
Rate this question:
Alpha a = x;
Foo f = (Delta)x;
Foo f = (Alpha)x;
Beta b = (Beta)(Alpha)x;
Rate this question:
00
0001
000120
00012021
Compilation fails.
An exception is thrown at runtime.
Rate this question:
Test end
Compilation fails.
Test runtime end
Test exception end
A Throwable is thrown by main at runtime.
Rate this question:
A
B
C
Ac
Abc
Rate this question:
The instance gets garbage collected.
The code on line 33 throws an exception.
The code on line 35 throws an exception.
The code on line 31 throws an exception.
The code on line 33 executes successfully.
Rate this question:
5,6
5,5
6,5
6,6
Rate this question:
No output
No output assert is on
Assert is on
No output An AssertionError is thrown.
Assert is on An AssertionError is thrown.
Rate this question:
Compilation fails.
Pi is bigger than 3.
An exception occurs at runtime.
Pi is bigger than 3. Have a nice day.
Pi is not bigger than 3. Have a nice day.
Rate this question:
The value "4" is printed at the command line.
Compilation fails because of an error in line 5.
Compilation fails because of an error in line 9.
A NullPointerException occurs at runtime.
A NumberFormatException occurs at runtime.
An IllegalStateException occurs at runtime.
Rate this question:
The equals method does NOT properly override the Object.equals method.
Compilation fails because the private attribute p.name cannot be accessed in line 5.
To work correctly with hash-based data structures, this class must also implement the hashCode method.
When adding Person objects to a java.util.Set collection, the equals method in line 4 will prevent duplicates.
Rate this question:
The hashCode method for a given class can be used to test for object equality and object inequality for that class.
The hashCode method is used by the java.util.SortedSet collection class to order the elements within that set.
The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class.
The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a Gaussian distribution.
The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval.
Rate this question:
Public int compareTo(Object o){/*more code here*/}
Public int compareTo(Score other){/*more code here*/}
Public int compare(Score s1,Score s2){/*more code here*/}
Public int compare(Object o1,Object o2){/*more code here*/}
Rate this question:
Remove line 14.
Replace line 14 with "int i = iter.next();".
Replace line 13 with "for (int i : intList) {".
Replace line 13 with "for (Iterator iter : intList) {".
Replace the method declaration with "sum(List intList)".
Replace the method declaration with "sum(List intList)".
Rate this question:
Compilation fails due to an error in line 23.
Compilation fails due to an error in line 29.
A ClassCastException occurs in line 29
A ClassCastException occurs in line 31.
The value of all four objects prints in natural order.
Rate this question:
Import utils.*;
Static import utils.*;
Import utils.Repetition.*;
Static import utils.Repetition.*;
Import utils.Repetition.twice();
Import static utils.Repetition.twice;
Static import utils.Repetition.twice;
Rate this question:
/test/Chess.class
/home/bob/Chess.class
/test/games/Chess.class
/usr/lib/games/Chess.class
/home/bob/games/Chess.class
Inside jarfile /opt/java/lib/Games.jar (with a correct manifest)
Inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)
Rate this question:
If the compile is successful, Utils.class is added to the source directory.
The compiler returns an invalid flag error.
If the compile is successful, Utils.class is added to the classes directory.
If the compile is successful, Utils.class is added to the bigProject directory.
Rate this question:
Java MainClass if run from the /apps directory
Java com.company.application.MainClass if run from the /apps directory
Java -classpath /apps com.company.application.MainClass if run from any directory
Java -classpath . MainClass if run from the /apps/com/company/application directory
Java -classpath /apps/com/company/application:. MainClass if run from the /apps directory
Java com.company.application.MainClass if run from the /apps/com/company/application directory
A class's finalize() method CANNOT be invoked explicitly.
Super.finalize() is called implicitly by any overriding finalize() method.
The finalize() method for a given object is called no more than once by the garbage collector.
The order in which finalize() is called on two objects is based on the order in which the two objects became finalizable
Rate this question:
Quiz Review Timeline (Updated): Mar 17, 2023 +
Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.
Wait!
Here's an interesting quiz for you.