scjp Questions

8

Solved

One of the correct answers from OCP Java SE 6 Programmer Practice Exams is: You can programmatically test wheather assertions have been enabled without throwing an AssertionError. How can I ...
Dripping asked 23/10, 2012 at 11:57

2

Solved

In studying for the Java certification test I learned that static initialization blocks run once when the class is loaded, in order of appearance within the source code, that instance initializatio...
Supplejack asked 16/12, 2013 at 20:9

10

Solved

I was just studying OCPJP questions and I found this strange code: public static void main(String a[]) { System.out.println(Double.NaN==Double.NaN); System.out.println(Double.NaN!=Double.NaN); }...
Jonas asked 11/1, 2012 at 13:2

7

Solved

Why in Java can we catch an Exception even if it is not thrown, but we can't catch it's subclass (except for "unchecked" RuntimeExceptions and it subclasses). Example code: class Test { public st...
Larrup asked 5/5, 2011 at 14:57

3

Solved

public class Java{ public static void main(String[] args){ final byte x = 1; final byte y = 2; byte z = x + y;//ok System.out.println(z); byte a = 1; byte b = 2; byte c = a + b; //Compiler...
Majewski asked 27/10, 2012 at 12:3

2

Solved

Select the three correct answers (valid declarations). (a) char a = '\u0061'; (b) char 'a' = 'a'; (c) char \u0061 = 'a'; (d) ch\u0061r a = 'a'; (e) ch'a'r a = 'a'; Answer: (a), (c) and (d) B...
Portwin asked 8/10, 2019 at 8:54

4

Solved

Can someone explain this code? public class SneakyThrow { public static void sneakyThrow(Throwable ex) { SneakyThrow.<RuntimeException>sneakyThrowInner(ex); } private static <T ext...
Bullwhip asked 26/12, 2012 at 9:40

6

Solved

I've just read through the chapter on method-local inner classes in the SCJP book, and I'm really struggling to think of any practical use for them. I've always been under the impression, that met...
Springy asked 4/4, 2011 at 19:39

6

I'm preparing for the SCJP (recently rebranded as OCPJP by Oracle) and one particular question that I got wrong on a mock exam has confused me, the answer description doesn't explain things clear e...
Bedstead asked 25/9, 2012 at 18:50

3

Solved

I am currently studying for the SCJP certification using the Sierra and Bates Study Guide and in many of the self tests (mock exam questions) I keep running into the same problem - I can't tell whe...
Sainted asked 5/7, 2010 at 12:40

4

Solved

How come the elements of priority queue are ordered according to natural order by default as it doesn't implement comparable interface? From the documentation, it says elements are ordered based on...
Greenleaf asked 6/5, 2015 at 8:59

7

Solved

I am reading for SCJP and I have a question regarding this line: Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifi...
Ascetic asked 2/8, 2012 at 8:54

4

Solved

Just when I thought I finally understood generics, I came across the following example: public class Organic<E> { void react(E e) { } static void main(String[] args) { //1: Organic<? ...
Owen asked 30/10, 2012 at 6:22

5

Solved

This question was taken from Kathy Sierra SCJP 1.6. How many objects are eligible for garbage collections? According to Kathy Sierra's answer, it is C. That means two objects are eligible for garb...
Sinistral asked 19/7, 2012 at 15:27

5

Solved

I read in the book for OCJP for Java6 the part with assertions. I reached the part where it gives me an overview of how the compiler reacts if the word 'assert' is used as keyword or as an identifi...
Sopping asked 22/9, 2012 at 19:27

7

In Which Cases it is a good coding practice to use implements serializable other than Writing & Reading object to/from file.In a project i went through code. A class using implements serializab...
Anglicism asked 20/7, 2015 at 18:51

4

Solved

I am working on Java Se 7 OCA and could not figure out why below code does not compile. aMethod call in main method gives compile error stating ambiguous method. Precedence rules between widening a...
Dimorph asked 19/3, 2013 at 6:57

3

Solved

I have been testing the char casting and I went through this: public class Test { public static void main(String a[]) { final byte b1 = 1; byte b2 = 1; char c = 2; c = b1; // 1- Working fine...
Disagreement asked 20/5, 2015 at 10:9

3

Solved

I have been trying a mock ocjp 6 test. I went though a question asking if the constructor is correct : 1- public Test8(){} 2- private void Test8(){} 3- protected Test8(int k){} 4- Test8(){} ...
Anthropomorphous asked 19/5, 2015 at 14:16

2

Solved

From page 291 of OCP Java SE 6 Programmer Practice Exams, question 25: public class Stone implements Runnable { static int id = 1; public void run() { id = 1 - id; if (id == 0) pick(); el...
Cargo asked 23/11, 2014 at 12:56

3

Solved

Please take a look at below example i cant understand the relation between char and byte byte b = 1; char c = 2; c = b; // line 1 Give me compilation Error because c is type of char and b is ty...
Curator asked 20/11, 2014 at 16:30

1

Solved

According to the SCJP6 (Page 507) i found that instance variables are assigned default values before the superclass constructors complete, i tried an example in Debugg mode but i saw that the super...
Wheeze asked 24/10, 2014 at 17:4

1

Solved

int primitivI[] = {1,1,1}; Integer wrapperI[] = {2,22,2}; 1. System.out.println(primitivI instanceof Object);//true 2. System.out.println(primitivI instanceof Object[]);//Compilation Error Why ??...
Pahlavi asked 10/10, 2014 at 5:24

4

Solved

Why is the output in this example 1? public static void main(String[] args){ int[] a = { 1, 2, 3, 4 }; int[] b = { 2, 3, 1, 0 }; System.out.println( a [ (a = b)[3] ] ); } I thought it wou...
Samellasameness asked 4/12, 2011 at 11:25

1

Solved

I have studied some books for OCPJP 7 certification and in the inner classes chapter there were some strange/incomplete informations. I've tried to create an interface inside a method, but it seems...
Sturtevant asked 7/8, 2014 at 10:43

© 2022 - 2024 — McMap. All rights reserved.