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.