Тема: Тести від SoftServe
1.) The figure shows the declaration of two classes that are in one package. In one of them a certain method main (...) determine what will be written to the output stream System.out as a result of the program.
public class A {
private int id;
private String name;
public A(int id, String name)
{
this.id = id;
this.name = name;
}
public String getName()
{
return name;
}
public String setName()
{
this.name = name;
}
}
public class ClassesPointers {
public static void main(String[] args) {
A objF = new A(1, "First");
A objS = new A(2, "Second");
objS = objF;
objF.setName("Third");
System.out.println(objS.getName());
}
}
Select one:
a. Compile error;
b. Third
c. Runtime error;
d. Second
e. First
2.)Please determine the value of variable named "s"
int s = 1;
int k = 0;
do {
s += 2;
} while(s != 100);
System.out.print("s= "+s);
Select one:
a. 99
b. Infinite loop;
c. 101
d. 100
3.)Please determine the value of variable named "s"
int s = 1;
for(int i = 5; i > 0; i--) {
s += i;
if(i != 0) { break; } }
System.out.print("s = " + s);
Select one:
a. 15
b. 16
c. 6
d. 5
4.)What will be the result of executing the following code?
boolean a = true;
boolean b = false;
boolean c = true;
if(a == true) {
if(b == true) {
if(c == true) {
System.out.println("1");
} else System.out.println("2");
} else if(a&&(b=c)) {
System.out.println("3");
}
else {
System.out.println("4");
}
Select one:
a. Runtime error.
b. "2" will be printed.
c. "4" will be printed.
d. Compilation error.
e. "3" will be printed.
f. "1" will be printed.
5.)How many errors does the following code contain?
Package A.B.C;
Public Class M {
Public Static Void Main(String[] Args) {
Long L = 0L;
System.Out.Println("Hello, World No" + L + "!");
}
}
Select one:
a. More than 14
b. Less than 7
c. 12
d. 14
e. 11
f. 9
g. 10
h. 13
i. 8
j. 7
6.)What is the output from the following code?
short i = 32766;
do {
System.out.print(i);
i++;
} while(i < 32767);
Select one:
a. Runtime error;
b. Compile error;
c. Iteration don't execute;
d. Executed one iteration;
e. Running one too many iteration;
7.)What are the differences between interfaces, abstract classes, classes, and instances?
Select one or more:
a. Abstract classes cannot be instantiated, but can contain variables, implemented methods, and unimplemented methods.
b. Interfaces are essentially a list of methods that implementations must possess, but have no code or member variables.
c. Instances (or objects) are specific examples of a particular class.
d. Classes contain variables and implemented methods only, and can be instantiated.
8.)What access modificators for classes present in Java
Select one or more:
a. protected
b. friend
c. private
d. public
9.)What is the output from the following code?
for(short i = 32766; i < 32767; i++) {
System.out.print(i);
}
Select one:
a. Iteration don't execute;
b. Compile error;
c. Executed one iteration;
d. Runtime error;
e. Running one too many iteration;
10.) What access modificator tell that it's a closed member of class?
Select one:
a. private
b. public
c. protected
d. friend