![placeholder image to represent content](/_next/image?url=%2Fassets%2Fquiz_default_logo.jpg&w=256&q=75)
Java Class Assessment 2
Quiz by Sunil Kumar V
Feel free to use or edit a copy
includes Teacher and Student dashboards
Measure skillsfrom any curriculum
Tag the questions with any skills you have. Your dashboard will track each student's mastery of each skill.
- edit the questions
- save a copy for later
- start a class game
- automatically assign follow-up activities based on students’ scores
- assign as homework
- share a link with colleagues
- print as a bubble sheet
- Q1
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?
atom granite
atom granite granite
atom granite atom granite
granite granite
120s - Q2
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?
foofoofoobarbar
foobarfoobarfoo
foofoofoobarfoo
foobarfoobarbar
120s - Q3
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?
It can beany class.
The class must be a subclass of the class Hypotenuse.
No class has access to base.
The class must belong to the geometry package.
120s - Q4
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?
321
32
23
123
120s - Q5
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?
bark
meow
An exception is thrown at runtime.
peep
120s