JavaScript and Java Programming Quiz

Test your knowledge of JavaScript objects, functions, and Math operations, along with Java inner classes including nested classes and anonymous inner classes.

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which is true about an anonymous inner class?

  1. It can extend exactly one class and implement exactly one interface.
  2. It can extend exactly one class and can implement multiple interfaces.
  3. It can extend exactly one class or implement exactly one interface.
  4. It can implement multiple interfaces regardless of whether it also extends a class.
Question 2 Multiple Choice (Single Answer)
class Boo {
    Boo(String s) {}
    Boo() {}
}
class Bar extends Boo {
    Bar() {}
    Bar(String s) {
        super(s);
    }
    void zoo() { 
         // insert code here      
    }  
}

which one create an anonymous inner class from within class Bar?

  1. Boo f = new Boo(24) { };
  2. Boo f = new Bar() { };
  3. Bar f = new Boo(String s) { };
  4. Boo f = new Boo.Bar(String s) { };
Question 3 Multiple Choice (Single Answer)

Which is true about a method-local inner class?

  1. It must be marked final.
  2. It can be marked abstract.
  3. It can be marked public.
  4. It can be marked static.
Question 4 Multiple Choice (Single Answer)

Which constructs an anonymous inner class instance?

  1. Runnable r = new Runnable() { };
  2. Runnable r = new Runnable(public void run() { });
  3. Runnable r = new Runnable { public void run(){}};
  4. System.out.println(new Runnable() {public void run() { }});
Question 5 Multiple Choice (Single Answer)
public class MyOuter {
    public static class MyInner {
        public static void foo() {}
    }
}

which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested class?

  1. MyOuter.MyInner m = new MyOuter.MyInner();
  2. MyOuter.MyInner mi = new MyInner();
  3. MyOuter m = new MyOuter(); MyOuter.MyInner mi = m.new MyOuter.MyInner();
  4. MyInner mi = new MyOuter.MyInner();
Question 6 Multiple Choice (Single Answer)

What is the output of the below JavaScript?
alert(Math.sqrt(-16));

  1. -4
  2. 4
  3. Error
  4. NaN
Question 7 Multiple Choice (Single Answer)

What is the output of the below JavaScript?

<script>  		
with(Math){  			  
     alert(pow(2,3));  		
}  	
</script>
  1. 8
  2. 9
  3. error
  4. 6
Question 8 Multiple Choice (Single Answer)

What is the output of the below JavaScript?

<script>  		
alert(parseInt("8.56") + " " + parseInt("8error"));  	
</script>
  1. Error
  2. 98
  3. 88
  4. 16
Question 9 Multiple Choice (Single Answer)

What is the output of the below JavaScript?
alert(parseFloat("8.56"));

  1. 8.56
  2. 9
  3. error
  4. NaN
Question 10 Multiple Choice (Single Answer)

What is the output of the below JavaScript?

<script>
    var currDate = new Date("30 September, 2011");
    alert(currDate.getMonth());
</script>
  1. 9
  2. 8
  3. 10
  4. error
Question 11 Multiple Choice (Single Answer)
<script>  		
function Book(id, name) {
    this.id = id;
    this.name = name;
}
var book = new Book("1001", "Head First JavaScript");
alert(book.id);
</script>
  1. 1001
  2. error
  3. Head First JavaScript
  4. id
Question 12 Multiple Choice (Single Answer)

What is the output of the below JavaScript?

<script>  		
var book = "Head First JavaScript";  		
alert(book.length);  	
</script>
  1. 21
  2. 20
  3. 22
  4. error
Question 13 Multiple Choice (Single Answer)
<script>  		
a = 10;  		
var b = 20;  		
var c = a + b;  		
alert(c);  	
</script>
  1. error
  2. 1020
  3. 30
  4. 20
Question 14 Multiple Choice (Single Answer)
<script>  		
var personObj = new Object();  		
personObj.firstname = "Jerome";  		
personObj.lastname = "Davin";  		
alert(personObj.firstname);  	
</script>
  1. Jerome
  2. Davin
  3. error
  4. firstname
Question 15 Multiple Choice (Single Answer)

What is the output of the below JavaScript?

<script>  		
var personObj = {firstname:"Jerome",lastname:"Davin"};  		
alert(personObj.lastname);  	
</script>
  1. Davin
  2. Jerome
  3. error
  4. lastname