wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exam qs- object orientation- help! 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 "exam qs- object orientation- help!" Watch "exam qs- object orientation- help!" New topic
Author

exam qs- object orientation- help!

sarim raza
Ranch Hand

Joined: Nov 02, 2000
Posts: 232
please explain, thanks!
1.What will be the result of attempting to run the following program?
public class Qaa75 {
public static void main(String args[]) {
String[][][] arr = {
{ {}, null },
{ { "1", "2" }, { "1", null, "3" } },
{},
{ { "1", null } }
};
System.out.println(arr.length + arr[1][2].length);
}
}
A]Program will terminate withArrayOutOfBounds Exception
B]Program will terminate withNullPointer Exception
C]4 printed to output
D]6 printed to output
E]7 printed to standard output

2.Which code fragments will succeed in printing the last argument given on the command line to the standard output, and exit gracefully with no output if no arguments are given?
CODE FRAGMENT A:
public static void main(String args[]) {
if (args.length != 0)
System.out.println(args[args.length-1]);
}
CODE FRAGMENT B:
public static void main(String args[]) {
try { System.out.println(args[args.length]); }
catch (ArrayIndexOutOfBoundsException e) {}
}
CODE FRAGMENT C:
public static void main(String args[]) {
int ix = args.length;
String last = args[ix];
if (ix != 0) System.out.println(last);
}
CODE FRAGMENT D:
public static void main(String args[]) {
int ix = args.length-1;
if (ix > 0) System.out.println(args[ix]);
}
CODE FRAGMENT E:
public static void main(String args[]) {
try { System.out.println(args[args.length-1]); }
catch (NullPointerException e) {}

3. What will be written to the standard output when the following program is run?
class Base {
int i;
Base() {
add(1);
}
void add(int v) {
i += v;
}
void print() {
System.out.println(i);
}
}
class Extension extends Base {
Extension() {
add(2);
}
void add(int v) {
i += v*2;
}
}
public class Qd073 {
public static void main(String args[]) {
bogo(new Extension());
}
static void bogo(Base b) {
b.add(8);
b.print();
}
}
A]9
B]18
C]20
D]21
E]22

4. interface I {
void setValue(int val);
int getValue();
}
DEFINITION A:
(a)class A extends I {
int value;
void setValue(int val) { value = val; }
int getValue() { return value; }
}
DEFINITION B:
(b)interface B extends I {
void increment();
}
DEFINITION C:
(c)abstract class C implements I {
int getValue() { return 0; }
abstract void increment();
}
DEFINITION D:
(d)interface D implements I {
void increment();
}
DEFINITION E:
(e)class E implements I {
int value;
public void setValue(int val) { value = val; }
}

5. Given the following code, which method declarations, when inserted at the indicated position, will not cause the program to fail compilation?
public class Qdd1f {
public long sum(long a, long b) { return a + b; }
// insert new method declaration here
}
A]public int sum(int a, int b) {return a + b;}
B]public int sum(long a, long b) { return 0;}
C]abstract int sum();
D]private long sum(long a , long b) { return a + b; }
E]public long sum(long a, int b) {return a + b; }

6. What will be written to the standard output when the following program is run?
public class Qcb90 {
int a;
int b;
public void f() {
a = 0;
b = 0;
int[] c = { 0 };
g(b, c);
System.out.println(a + " " + b + " " + c[0] + " ");
}
public void g(int b, int[] c) {
a = 1;
b = 1;
c[0] = 1;
}
public static void main(String args[]) {
Qcb90 obj = new Qcb90();
obj.f();
}
}
A]000
B]001
C]010
D]100
E]101
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3285
    
    7
whops..looks like you've got hold of a mock exam without explanations!
Trying 3 things will help you the most:
1. Looking into the API
2. Compiling the code.
3. After compiling, it doesn't take much time to run it!
If you still need help (in fact most of the time you'll not), posting one topic per thread will probably get you better explanations.
-Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
UPENDRA KANE
Greenhorn

Joined: Sep 29, 2000
Posts: 24
These all are Qs from Mughal's book and you will find a neat explanation of these Qs overe there.


Regular
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Any where exactly IS over there???


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: exam qs- object orientation- help!