Documente Academic
Documente Profesional
Documente Cultură
) MWF: 12:30
P.M. – 1:30 P.M. BSIT – 3
2. What will happen if you try to compile and run the following code
public class MyClass {
public static void main(String arguments[]) {
amethod(arguments);
}
public void amethod(String[] arguments) {
System.out.println(arguments);
System.out.println(arguments[1]);
}
}
a) error Can't make static reference to void a method.
b) error method main not correct
c) error array must include parameter
d) a method must be declared with String
e) none of the above
3. Which of the following will compile without error
a)
import java.awt.*;
package Mypackage;
class Myclass {}
b)
package MyPackage;
import java.awt.*;
class MyClass{}
c)
/*This is a comment */
package MyPackage;
import java.awt.*;
class MyClass{}
d) both a and b
Answer # 1
e) int i=10;
Explanations:
a) float f=1.3;
Will not compile because the default type of a number with a floating point component is a double. This would
compile with a cast as in
float f=(float) 1.3
b) char c="a";
Will not compile because a char (16 bit unsigned integer) must be defined with single quotes. This would
compile if it were in the form
char c='a';
c) byte b=257;
Will not compile because a byte is eight bits. Take of one bit for the sign component you can define numbers
between
-128 to +127
Answer # 2
Because main is defined as static you need to create an instance of the class in order to call any non-static
methods. Thus a typical way to do this would be.
MyClass m=new MyClass();
m.amethod();
b) is an attempt to confuse because the convention is for a main method to be in the form
String argv[]
That argv is just a convention and any acceptable identifier for a string array can be used.
Answer # 3
e) is just a nonsense
Answer # 4