placeholder image to represent content

Java Class Assessment 2

Quiz by Sunil Kumar V

Our brand new solo games combine with your quiz, on the same screen

Correct quiz answers unlock more play!

New Quizalize solo game modes
5 questions
Show answers
  • 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

Teachers give this quiz to your class