Quiz
Coffee001
Questions in this quiz (4)
1package com.protoeffect;
public class Test {
static int count = 0;
int i = 0;
public void changeCount(){
while(i<5){
i++;
count++;
}
}
}
public class Main {
public static void main(String[] args) {
Test check1 = new Test();
Test check2 = new Test();
check1.changeCount();
check2.changeCount();
System.out.println(check1.count + " : " + check2.count);
}
}- A10 : 10
- B5 : 5
- C5 : 10
- DCompilation fails
2package com.protoeffect;
public class Main {
public static void main(String[] args) {
String product = "Pen";
product.toLowerCase();
product.concat(" BOX".toLowerCase());
System.out.println(product.substring(4,6));
}
}- Abox
- Bnbo
- Cbo
- Dnb
- EAn exception is thrown at runtime.
3Which three are advantages of the Java exception mechanism?
- AImproves the program structure because the error handling code is separated from the normal program function.
- BProvides a set of standard exceptions that covers all the possible errors.
- CImproves the program structure because the programmer can choose where to handle exceptions.
- DImproves the program structure because exceptions must be handled in the method in which they occurred.
- EAllows the creation of new exceptions that are tailored to the particular program being created.
4<PRE>
package com.protoeffect;
public class Person {
String name;
int age = 25;
public Person(String name) {
this(); //line n1
setName(name);
}
public Person(String name, int age){
Person(name); //line n2
setAge(age);
}
//setter and getter methods go here
public String show(){
return name + " " + age + " " + number;
}
}
package com.protoeffect;
public class Main {
public static void main(String[] args) {
Person p1 = new Person("Jesse");
Person p2 = new Person("Walter",52);
System.out.println(p1.show());
System.out.println(p2.show());
}
}
</PRE>- AJesse 25
Waller 52 - BCompilation fails only at line n1
- CCompilation fails only at line n2
- DCompilation fails at both line n1 and line n2
- AJesse 25
Information
- Description
- Quiz on Coffee001, created by James Fraley on 25/01/2017.
- Author
- James Fraley
- Language
- English
- Views
- 0
- Tags
- Rating
- No ratings yet Rate this quiz