O'Reilly logo

Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) by Marcus Green, Bill Brogden

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Practice Exam

Question 1 Given the following definition of the Demo class and the DerivedDemo class:
1. public class Demo extends Object {
2.   String Title ;
3.   public Demo( String t ){
4.      Title = t ;
5.   }
6.   public void showTitle() {
7.    System.out.println("Title is " + Title) ;
8.   }
9. }
10. class DerivedDemo extends Demo {
11.    public void setTitle( String  tt )
         { Title = tt ; }
12. }

What happens if you try to compile this code, create a DerivedDemo object, and immediately call the showTitle method of that object?

  • A. The message “Title is null” is written to standard output.

  • B. The compiler complains about the DerivedDemo class.

  • C. A NullPointerException is thrown in line 7.

Question 2 Which of the following class declarations are not correct ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required