aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IrixTech Mock Exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "IrixTech Mock Exam" Watch "IrixTech Mock Exam" New topic
Author

IrixTech Mock Exam

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Mock Questions from Practice test 1 @ http://www.irixtech.com

Hi sorry this post is so long...I'm just really dubious of this mock exam..

What is the output of the following code when compiled and run ?


Answer:123123

How can this be when the join method has no parameter??

Also:

Given the following,



which is true about the classes depicted above ?

I said that class B is tightly encapsulated.The answer said neither.Isn't B's instance variable marked as private??

Another one:
What will happen if run the following code?



I said the output will be false and false.They said false null.Why null!?!?
They were both declared and accessed in exacty the same way...

Another one:


Here they say that there is a compiler error because x is not initialised.I'm not too sure about this one...

Another:
A source code file contains the following lines:


Doesn't there need to be a public class matching the name of the java file?

And another:



They say compiler error on line 08...Cannot access protected member f.
But doesn't protected allow a subclass to access the protected member as long as you dont modify it??
[ December 23, 2008: Message edited by: Duran Harris ]

===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Duran you should Use One Thread Per Question

Anyways let me try to solve your queries

the join method has no parameter??


What's the problem with join having no parameters. The code starts a thread and then joins it

19. t1.start( );
20. t1.join( );
21. ...

So the execution will reach to statement 21 when the thread t1 has completed execution i.e. its run method completes.

I said that class B is tightly encapsulated.


But B is-a A. Since A is not encapsulated, so neither is B. The field x breaks the encapsulation.

Boolean[ ] b1 = new Boolean[10];
boolean[ ] b2 = new boolean[10];

They were both declared and accessed in exacty the same way...


Note that one of the array is a Boolean i.e. array of references. Elements in an array of booleans are automatically initialized to false. And elements in an array of references are always initianlized to null.

Here they say that there is a compiler error because x is not initialised.I'm not too sure about this one...


If your class has a final field, it must be initialized before or in the last statement of every constructor (if a constructor calls another constructor then that constructor doesn't need and in fact cannot initialize it).

Doesn't there need to be a public class matching the name of the java file?


Not necessarily. The rule says that if you have a public class, it must be stored in a .java file with the same name as the public class. So you cannot have two public top level classes in the same source file.

But doesn't protected allow a subclass to access the protected member??


You can access a protected inherited member outside the package only through inheritance. You cannot use an instance of the super class to access it...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
M Srilatha
Ranch Hand

Joined: Aug 27, 2008
Posts: 137
Reg 1st question: How can this be when the join method has no parameter??


First of all:
t1 and t2 are created two different objects of R. So they wont block each other.

And there is a call t1.join() just after starting t1. That means main thread waits till the time t1 finishes its task. So run() method will be executed once and prints 123. After run() method is executed, main thread resumes and starts t2. As t2 is created with a different object of R, run() method will print 123. Hence the output is: 123123.

I am not sure why you are confused with join() with no parameters.
if you call join() with no parameters, the waiting thread will become runnable just after the other thread has finished.
if you specify the maximum time that a thread can wait for another thread to finish its task, the waiting thread will become runnable after the time has elapsed if the other thread has not finished before that.

Hope this is clear!


Thanks,<br />Srilatha M
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
How can this be when the join method has no parameter??


Why, join() does should take any parameter.

t1.join() internally calls join(0).
public final void join() throws InterruptedException {
join(0);
}


Here 0 parameter indicates that current thread should wait for infinite time until t1 thread does not complete its execution.


SCJP 6
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Aaah...wow I made dumb mistakes.
Okay so calling t.join() joins the currently executing thread to t?I forgot about main..?Doesn't join have a parameter of(Thread t) or is it optional...I really must go over threads tonight

If your class has a final field, it must be initialized before or in the last statement of every constructor (if a constructor calls another constructor then that constructor doesn't need and in fact cannot initialize it).

So what exactly happens when you declare an instance reference variable as final like this=> final int x;
=> does it only become immutable once a value is
=> assigned to it??
[ December 23, 2008: Message edited by: Duran Harris ]
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

it becomes a compile time constant.
Compiler replaces that variable with its value once it is compiled


SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

If you declare a constant in your class, it must be initialized before constructors are over. So this code will not compile as z is not initialized in the no-arg constructor

Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
But if you declare a final AND static variable, then it must be initialized either as part of its declaration, or in a static initializer block exclusively.


All code in my posts, unless a source is explicitly mentioned, is my own.
 
Don't get me started about those stupid light bulbs.
 
subject: IrixTech Mock Exam