Академический Документы
Профессиональный Документы
Культура Документы
D
Given: A. Line 16
11. public void genNumbers() { B. Line 17
12. ArrayList numbers = new ArrayList(); C. Line 18
13. for (int i=0; i<10; i++) { D. Line 19
14. int value = i * ((int) Math.random()); E. The object is NOT a candidate for
15. Integer intObj = new Integer(value); garbage collection.
16. numbers.add(intObj);
17. }
18. System.out.println(numbers);
19. }
Which line of code marks the earliest point
that an object referenced by intObj
becomes a candidate for
garbage collection?
D
• What is object,class,polymorphism,inheritance.
explain with example.
D
Solution:
public int update(int quantity,int adjust){
quantity=quantity+adjust;
return quantity;
}
printing Info!!!!!!!!!
Predict output
Predict output
public class Test
{
public static void main(String args[])
{ Test obj= null;
obj.printData();
obj.printName(“Sachin”);
}
private static void printData()
{System.out.println("Hello World!!!! ");
}
private void printName(String name)
{
System.out.print("Hello "+ name); }
}
Hello World!!!!!
NullPointerException
Interfaces
Solution:
interface Reloadable{
public void reload();
}
class Edit{
public void edit(){/* Edit Here*/}
}
interface Displayable
extends Reloadable {
public void display();
}
interface Rideable { public class Camel implements Rideable {
String getGait(); int weight = 2;
} public static void main(String[] args) {
new Camel().go(8);
}
void go(int speed) {
++speed;
weight++;
int walkrate = speed * weight;
System.out.print(walkrate + getGait());
}
String getGait() {
return " mph, lope";
}
}
Compilation Error
Given A. final
11. public interface Status { B. static
12. /* insert code here */ int C. native
MY_VALUE = 10; D. public
13. } E. private
Which three are valid on line F. abstract
12? G. protected
D, B A
Solution:
interface Reloadable{
public void reload();
}
class Edit{
public void edit(){/* Edit Here*/}
}
interface Displayable
extends Reloadable {
public void display();
}
Given the following, C. abstract class Class2
1. interface Base { implements Base { }
2. boolean m1 (); D. abstract class Class2
3. byte m2(short s); implements Base {
4. } public boolean m1() { return
(true); } }
Which code fragments will compile?
(Choose all that apply.) E. class Class2 implements
A. interface Base2 implements Base { } Base {
B. abstract class Class2 extends Base { boolean m1() { return false; }
public boolean m1() { return true; } }
byte m2(short s) { return 42; } }
C&D
Exception Handling
1. What type exceptions do not require try-catch blocks?
2. throw key word can be used to throw object of any class from try block?.
3. The block of code which will be executed, if there is a run time error or not
COMPILATION Fails
Given: Under which three circumstances
31. // some code here will the code on line 37 be executed?
(Choose three.)
32. try { A. The instance gets garbage
33. // some code here collected.
34. } catch (SomeException se) B. The code on line 33 throws an
{ exception.
35. // some code here C. The code on line 35 throws an
exception.
36. } finally { D. The code on line 31 throws an
37. // some code here exception.
38. } E. The code on line 33 executes
successfully.
B&E
class test2{ What is the result?
public static void main(String[] args) A. test
{
try {
B. Exception
args = null; C. Compilation fails.
args[0] = "test"; D. NullPointerException
System.out.println(args[0]);
}
catch (Exception ex) {
System.out.println("Exception");
}
catch (NullPointerException npe) {
System.out.println("NullPointerExce
ption");
} }}
C
try { What is the result if a
34. // some code here NullPointerException occurs
35. } catch on line 34?
(NullPointerException e1) { A. c
36. System.out.print("a"); B. a
37. } catch (RuntimeException C. ab
e2) { D. ac
38. System.out.print("b"); E. bc
39. } finally { F. abc
40. System.out.print("c");
41. }
ac