
Java Class Assessment 2
Quiz by Sunil Kumar V
Tag the questions with any skills you have. Your dashboard will track each student's mastery of each skill.
Given:
5. class Atom{
6. Atom() { System.out.print("atom "); }
7. }
8. class Rock extends Atom {
9. Rock(String type) { System.out.print(type); }
10. }
11. public class Mountain extends Rock {
12. Mountain(){
13.super("granite ");
14. new Rock("granite ");
15. }
16. public static void main(String[] a) { newMountain(); }
17. }
What is the result?
Given:
1. public class Base {
2. public static final String FOO ="foo";
3. public static void main(String[] args){
4. Base b = new Base();
5. Sub s = new Sub();
6. System.out.print(Base.FOO);
7. System.out.print(Sub.FOO);
8. System.out.print(b.FOO);
9. System.out.print(s.FOO);
10. System.out.print(((Base)s).FOO);
11. } }
12. class Sub extends Base {public static final String FOO="bar";} What is the result?
Given:
1. package geometry;
2. public class Hypotenuse {
3. public InnerTriangle it = new InnerTriangle();
4. class InnerTriangle {
5. public int base;
6. public int height;
7. }
8. }
Which statement is true about the class of an object that can reference the variable base?
Given:
21. abstract class C1{
22. public C1() { System.out.print(1); }
23. }
24. class C2 extends C1 {
25. public C2() { System.out.print(2); }
26. }
27. class C3 extends C2 {
28. public C3() { System.out.println(3);}
29. }
30. public class Ctest {
31. public static void main(String[] a) { newC3(); }
32. }
What is the result?
Given:
11. class Animal{ public String noise(){ return "peep"; } }
12. class Dog extends Animal {
13. public String noise(){ return "bark"; }
14. }
15. class Cat extends Animal {
16. public String noise(){ return "meow"; }
17. }
...
30. Animal animal= new Dog();
31. Cat cat = (Cat)animal;
32. System.out.println(cat.noise());
What is the result?