File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes questions from java prepare 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 "questions from java prepare" Watch "questions from java prepare" New topic
Author

questions from java prepare

shabbir zakir
Ranch Hand

Joined: Nov 12, 2000
Posts: 183
1.Which of the following are legal Java programs. Select all the correct answer.
A.// The comments come before the package
package pkg;
import java.awt.*;
class C{}
B.package pkg;
import java.awt.*;
class C{}
C.package pkg1;
package pkg2;
import java.awt.*;
class C{}
D.package pkg;
import java.awt.*;
E.import java.awt.*;
class C{}
F.
the correct answers are a,b,d,e.
how d can be a correct answer.in the explanation they have given that it is an empty file.what is the meaning of that.And how do you save the file at d.
2.Which of the following statements are correct. Select all correct answers.
A.A Java program must have a package statement.
B.A package statement if present must be the first statement of the program (barring any comments).
C.If a Java program defines both a package and import statement, then the import statement must come before the package statement.
D.An empty file is a valid source file.
E.A Java file without any class or interface definitions can also be compiled.
F.If an import statement is present, it must appear before any class or interface definitions
The correct answers are
b, d, e, f.
my question is they have given option e as correct.How do a java
file without any class or interface defination can be compiled.

3.What would be the results of compiling and running the following class. Select the one correct answer.

class test {
public static void main() {
System.out.println("test");
}
}

A.The program does not compile as there is no main method defined.
B.The program compiles and runs generating an output of "test"
C.The program compiles and runs but does not generate any output.
D.The program compiles but does not run.
The correct answers is d
how does the program cannot run.the output is test.

4.Given a one dimensional array arr, what is the correct way of getting the number of elements in arr. Select the one correct answer.
A.arr.length
B.arr.length - 1
C.arr.size
D.arr.size - 1
E.arr.length()
F.arr.length() - 1
the answer is A.
length() is a method. so how can A is the right answer.E is the right answer.
5. Which of the following are legal declaration and definition of a method. Select all correct answers.
A.void method() {};
B.void method(void) {};
C.method() {};
D.method(void) {};
E.void method {};
the correct answer given is only E.
while a is also the right answer.
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
Here I'll try to answer these the best I can:
I'll start with the last one and work my way up.
5. A. is the only correct answer. E. is missing the parentheses after the method name. I believe this is a typo.
4. A. is again the right answer. If you consult the Jdk documentation you'll find that the only way to find the length of an array is with "<arrayname>.length". So for an array named arr, arr.length is the way to find out how big it is.
3. will compile fine because you define a method named "main" correctly but every program needs a public static void main(String args[]){} to compile and run. You've overidden this method from superclass Object.
2. Try it yourself, and you'll see that e is correct as well. This is often the best way to answer you're own questions. Write a program and see if it'll work. It's also great practice.
1. this is also correct. Try it yourself. put a package statement in followed by a legal import statement. then name the file correctly such as blue.java and compile it. The file will compile, but it won't give off a file named blue.class since there is no such class defined.
karan roy
Greenhorn

Joined: Dec 09, 2000
Posts: 13
i am giving the answer of the 4th one.
u r absolutely right when u say that .length()is the method to find the length-but the length of what??
it is used to find the length of a String.
to find the length of an array,we always use .length
w/out any parentheses.
 
Don't get me started about those stupid light bulbs.
 
subject: questions from java prepare
 
Similar Threads
5 javaprepare questions
Doubt from javaprepare.com
Doubts from javaprepare sample test
Legal java program?
Javaprepare.com - Questions - Language Fundamentals