Keyword

Result: 191 questions

Which interface does java.util.Hashtable implement?

Quiz

What will be the output of the program?

package foo; 
import java.util.Vector; /* Line 2 */
private class MyVector extends Vector 
{
    int i = 1; /* Line 5 */
    public MyVector() 
    { 
        i = 2; 
    } 
} 
public class MyNewVector extends MyVector 
{
    public MyNewVector () 
    { 
        i = 4; /* Line 15 */
    } 
    public static void main (String args []) 
    { 
        MyVector v = new MyNewVector(); /* Line 19 */
    } 
}
Quiz

Which method must be defined by a class implementing the java.lang.Runnable interface?

Quiz

Which of the following statements is true?

  1. If assertions are compiled into a source file, and if no flags are included at runtime, assertions will execute by default.
  2. As of Java version 1.4, assertion statements are compiled by default.
  3. With the proper use of runtime arguments, it is possible to instruct the VM to disable assertions for a certain class, and to enable assertions for a certain package, at the same time.
  4. When evaluating command-line arguments, the VM gives -ea flags precedence over -da flags.
Quiz

What will be the output of the program ?

#include<stdio.h>

    struct course
    {
        int courseno;
        char coursename[25];
    };
int main()
{
    struct course c[] = { {102, "Java"}, 
                          {103, "PHP"}, 
                          {104, "DotNet"}     };

    printf("%d ", c[1].courseno);
    printf("%s\n", (*(c+2)).coursename);
    return 0;
}
Quiz

What does the following code print to the console?

function blabbermouth() { };
console.log(blabbermouth.name);

 

Answer:

"blabbermouth"

Functions have a name property that returns the name of a function. JavaScript functions are objects and can have properties like any other object.

View

What does the following function print to the console?

function a(x, y, z) {
  return z;
}
console.log(a("blah"));

Answer:

undefined

When too few arguments are supplied to a function, JavaScript assigns the missing arguments to undefined.

View

What does the following code print to the console?

function c(f) {
  return f();
}
function blub() {
  return "monsters";
}
c(blub);

Answer:

"monsters"

The c() function takes a callback function as a parameter. blub is passed to c() as an argument and is invoked within the body of c().

Functions are "first class" in JavaScript because they can be passed as parameters and stored in data structures.

View

What does the following code print to the console?

result = function surfer() {
  return this === window;
}();
console.log(result);

Answer:

true

There are four different ways to invoke functions in JavaScript and this example demonstrates invocation as a function. The keyword "this" equals window for functions that are invoked as functions.

View

The following code illustrates how to define a constructor function and use the constructor function to create an object.

function Mammal() {
  this.warm_blooded = true;
  this.scaly = false;
}
var fido = new Mammal();

Print the scaly property of the fido object to the console.

Answer:

console.log(fido.scaly);

Constructor functions are specialized JavaScript functions for creating objects. Notice that the fido object could also be created with object literal notation.

View

Use object literal notation to create an object assigned to the spot variable, similar to the following constructor function.

function Mammal() {
  this.warm_blooded = true;
  this.scaly = false;
}
var spot = new Mammal();

Answer:

var spot = {
  warm_blooded: true,
  scaly: false  
}

Constructor functions and object literal notation can both be used to create JavaScript objects. Constructor functions are better when multiple similar objects are created, but both object construction techniques can be used to make JavaScript objects.

View

What does the following code print to the console?

function Hat() {
  var brand = "shhh can't tell";
}
var my_hat = new Hat();
console.log(my_hat.brand);

Answer:

undefined

brand is a private variable in the Hat() constructor function, so it can only be accessed by functions within the constructor function. Remember that JavaScript functions have function scope meaning that variables defined in the function are only available within the function itself.

View

The prototype property of constructor functions can also be set to add methods to objects created by constructor functions. JavaScript functions are objects and the prototype property can be used to add methods to the objects that are created by constructor functions.

function Dog(name) {
  this.name = name;
}

Dog.prototype = {
  constructor: Dog,
  bark: function () { return "ruff ruff" }
}

var rover = new Dog("red rover");
console.log(rover.name);  // returns "red rover"
What does the following line print to the console?
console.log(rover.bark());

Answer:

"ruff ruff"

The prototype design pattern is used to JavaScript to give methods to objects created by constructor functions.

View

Type the "this" keyword into the JavaScript web console of your favorite browser (hopefully Chrome or Firefox) and explain what is returned.

Answer:

this  // the window object is returned

The global object is created when the JavaScript interpreter starts and it creates global properties (i.e. NaN), global functions (i.e. parseInt()), built-in constructor functions (Array()), and global objects (Math). The global object for client-side JavaScript is called window.

View

What does the following line return when typed into the JavaScript web console of an internet browser?

this === window

Answer:

true

window is a keyword that refers to the global object. this refers to different objects in different contexts, but it refers to the window object in the top level namespace.

View

Invoke the zombies function.

function zombies() {
  return "We like to eat people";
}

Answer:

zombies();

Invoking a function is just a fancy way to say "running a function" or "executing a function". JavaScript functions are invoked by adding () to the end of the function name.

View

What does the following example print to the console?

console.log((function (x, y) { return x + y })(3, 4));

Answer:

7

The anonymous function in this example is defined and invoked on the same line. JavaScript functions are frequently invoked immediately after they are defined, so be prepared to see this technique used frequently.

View

What does the following example print to the console?

var globalObject = window;
function nestedExample() {
  function innerFunction () {
    return this === globalObject;
  }
  return innerFunction();
}
console.log(nestedExample());

Answer:

true

Due to a design flaw in the language, inner functions use the function invocation context, not the method invocation context, so the value of "this" in the innerFunction() equals the globalObject. Additional quirks and complicated features of the JavaScript language will be covered in subsequent quizzes.

View

Explain what the following code prints to the console.

function pirate () {
  return this;
}
console.log(pirate());

Answer:

The pirate() function returns the global window object. The global window object is created by the JavaScript interpreter when it is started to store built-in constructor functions, global constants, and global properties. When functions are invoked as functions (i.e. they are in the global namespace and are not part of an object or constructor function), the value of the this keyword is the global object.

View

Following program have compilation error, can you guess root cause of it?

abstract class VQCourse {
    public String courseName;
    public String courseID;
} public class VirtuQCourseProvide extends VQCourse {

    public static void main(String[]args) {
        VQCourse course1 = new VQCourse();
         course1.courseID = "0001";
         course1.courseName = "JAVA";
         System.out.println(course1.toString());
}}
Quiz

© 2017 QuizBucket.org