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.
Questions
Which is true about an anonymous inner class?
- It can extend exactly one class and implement exactly one interface.
- It can extend exactly one class and can implement multiple interfaces.
- It can extend exactly one class or implement exactly one interface.
- It can implement multiple interfaces regardless of whether it also extends a class.
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?
- Boo f = new Boo(24) { };
- Boo f = new Bar() { };
- Bar f = new Boo(String s) { };
- Boo f = new Boo.Bar(String s) { };
Which is true about a method-local inner class?
- It must be marked final.
- It can be marked abstract.
- It can be marked public.
- It can be marked static.
Which constructs an anonymous inner class instance?
- Runnable r = new Runnable() { };
- Runnable r = new Runnable(public void run() { });
- Runnable r = new Runnable { public void run(){}};
- System.out.println(new Runnable() {public void run() { }});
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?
- MyOuter.MyInner m = new MyOuter.MyInner();
- MyOuter.MyInner mi = new MyInner();
- MyOuter m = new MyOuter(); MyOuter.MyInner mi = m.new MyOuter.MyInner();
- MyInner mi = new MyOuter.MyInner();
What is the output of the below JavaScript? alert(Math.sqrt(-16));
- -4
- 4
- Error
- NaN
What is the output of the below JavaScript?
<script>
with(Math){
alert(pow(2,3));
}
</script>
- 8
- 9
- error
- 6
What is the output of the below JavaScript?
<script>
alert(parseInt("8.56") + " " + parseInt("8error"));
</script>
- Error
- 98
- 88
- 16
What is the output of the below JavaScript? alert(parseFloat("8.56"));
- 8.56
- 9
- error
- NaN
What is the output of the below JavaScript?
<script>
var currDate = new Date("30 September, 2011");
alert(currDate.getMonth());
</script>
- 9
- 8
- 10
- error
<script>
function Book(id, name) {
this.id = id;
this.name = name;
}
var book = new Book("1001", "Head First JavaScript");
alert(book.id);
</script>
- 1001
- error
- Head First JavaScript
- id
What is the output of the below JavaScript?
<script>
var book = "Head First JavaScript";
alert(book.length);
</script>
- 21
- 20
- 22
- error
<script>
a = 10;
var b = 20;
var c = a + b;
alert(c);
</script>
- error
- 1020
- 30
- 20
<script>
var personObj = new Object();
personObj.firstname = "Jerome";
personObj.lastname = "Davin";
alert(personObj.firstname);
</script>
- Jerome
- Davin
- error
- firstname
What is the output of the below JavaScript?
<script>
var personObj = {firstname:"Jerome",lastname:"Davin"};
alert(personObj.lastname);
</script>
- Davin
- Jerome
- error
- lastname