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 another Questions. 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 "another Questions." Watch "another Questions." New topic
Author

another Questions.

Amisha Shah
Ranch Hand

Joined: Mar 03, 2006
Posts: 33
Question:
in order for Test program to be compiled and run , which of the following must be true ?
A.the Test class must be defined in Test.java
B. Test must be declared public
C. Test must have correctly formed main() method
D. Test must import java. lang

Question:
Which of the following are true ?
A. if a package statement is included in a source code file , it must appear as the firsr non-blank line.
B.if an import statement is included in a source code file , it must appear as the firsr non-blank line.
C.if a main() method is included in a source code file , it must appear as the firsr non-blank line.
D. if a public interface is declared in a source code file , it must have same name as the source code file.

please tell me what are the perfect ans of above Qustions.


Amisha Shah.<br />SCJP 1.4
gaurav singhal
Ranch Hand

Joined: Nov 18, 2005
Posts: 135
Question:
in order for Test program to be compiled and run , which of the following must be true ?
A.the Test class must be defined in Test.java
B. Test must be declared public
C. Test must have correctly formed main() method
D. Test must import java. lang


Ans to this question is C


Question:
Which of the following are true ?
A. if a package statement is included in a source code file , it must appear as the firsr non-blank line.
B.if an import statement is included in a source code file , it must appear as the firsr non-blank line.
C.if a main() method is included in a source code file , it must appear as the firsr non-blank line.
D. if a public interface is declared in a source code file , it must have same name as the source code file.


According to me the ans to this question is A

It is relative see I assume that if there is package statement then it always come in first line. But if there is no package statement then the import statement comes in first statement.
Sreeram Desigan
Greenhorn

Joined: Apr 07, 2006
Posts: 23
Dear Amisha,
According to me the answer for first question is both A and C because if C is true then A should also be true. That is if test class has a main method then the source file should be named as test.
For the second question the answers are A and D.
Am very sure these are the correct answers. If package statement is present then it must be the first non comment statement of the program.
And if a program has a public interface then the source file should be named as the interface name else compile time error occurs.
Vaibhav Choudhary
Greenhorn

Joined: Apr 10, 2006
Posts: 5
1. No, for running the java file there is no need of being the class and .java file have the same name.

when we are doing javac, we need the java file name and when we are doing java, we need the class name which contain main method.

Yes, for running the program, main should be defined properly.


2. For second one, ya package should be the first line, but before package one can write the comments, so its not neccesary to be the first non-blank line.

Name of the interface must be same .. so D is correct.
kuturam chakraborty
Greenhorn

Joined: Jan 23, 2006
Posts: 25
hi all,

i dont understand why the public interface should have the same name as the source code file.
Nilesh Deshpande
Ranch Hand

Joined: Jan 11, 2006
Posts: 36
Its not only interface but if you declare a class with public, you will have to save that in the java file with the same name. Also you can declare 2 public interface in the same java file.
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
hi,
you can't have two public interface in the same source file, my source file was Inter1.java :

compiler error....


The man who makes no mistakes does not usually make anything<br /> <br />>>> SCJP 5.0 >> SCJD B&S <<< In progress
Gunj Agarwal
Greenhorn

Joined: Jan 29, 2006
Posts: 16
for first q? if i have another class that has a main method along with the test class then I can compile this file with test class and also run it..in that case both are not suitable......
 
jQuery in Action, 2nd edition
 
subject: another Questions.