File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

another Questions.

 
Amisha Shah
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
gaurav singhal
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

i dont understand why the public interface should have the same name as the source code file.
 
Nilesh Deshpande
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 286
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
you can't have two public interface in the same source file, my source file was Inter1.java :

compiler error....
 
Gunj Agarwal
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic