Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

SCJP SE 5.0 official exam by sun

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the link to the Official Test Exam by Sun

http://www.sun.com/training/certification/assessment/index.jsp

I propose to response all the question here, and add a little description/explanation to them ...
 
podonga poron
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will start ..

1. Given the two source files:

1. package com.sun;
2. public class PkgAccess {
3. public static int tiger = 1414;
4. }
And:

1. import static com.sun.PkgAccess.*;
2.
3. public class PkgAccess2 {
4.
5. int x1 = PkgAccess.tiger;
6. int x2 = tiger;
7. int x3 = com.sun.PkgAccess.tiger;
8. int x4 = sun.PkgAccess.tiger;
9. }

Which two are true? (Choose two.)

1 - The PkgAccess2 class compiles.
2 - Compilation fails due to an error on line 5.
3 - Compilation fails due to an error on line 6.
4 - Compilation fails due to an error on line 7.
5 - Compilation fails due to an error on line 8.
6 - The PkgAccess and PkgAccess2 classes both compile.

Answer: 2 and 5 are true.

Explanation : When you say import static com.sun.PkgAccess.*; you are importing every static value of the class PkgAccess, so you can call that value using

com.sun.PkgAccess.tiger // full path to access static "tiger" variable
tiger // use directly the static variable (because we import it !)

you CAN'T SAY

sun.PkgAccess.tiger // because the path is incorrect
PkgAccess.tiger // same as above
[ June 20, 2008: Message edited by: podonga poron ]
 
podonga poron
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2. Given:

1. interface Animal {
2. void eat();
3. }
4.
5. // insert code here
6.
7. public class HouseCat implements Feline {
8. public void eat() { }
9. }
And the following three interface declarations:
interface Feline extends Animal { }
interface Feline extends Animal { void eat(); }
interface Feline extends Animal { void eat() { } }
How many, inserted independently at line 5, will compile?

1 - 0
2 - 1
3 - 2
4 - 3

The Answer is = 3

Explanation: An interface doesn't necessary have to implements methods, so knowing that you can say ..

interface Feline extends Animal { } /* it doesn't implement the Animal methods but is fine since its an interface */

interface Feline extends Animal { void eat(); } /* implements the method eat () */

BUT if you say

interface Feline extends Animal { void eat() { } } /* we have an error here INTERFACE METHODS CAN'T HAVE A BODY, can't have "{}", so it's wrong */
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic