Create Software Components 

Using Java Level 2

 

 

Course Info

Scheme

Resources

Tutorials

Java Demos

Utilities

Links


 

    Quiz 4

Data Types, Variables & Constants

There are 15 questions

Question 1.         

Which one of the following would be the best suitable type for a variable that stores the number of children a person has? 

(a)   boolean

(b)   int

(c)    float

(d)   String

Question 2.         

Which one of the following would be a suitable type for a variable  that stores a personís last name? 

(a)   boolean

(b)   int

(c)   float

(d)   String

Question 3.         

Which of the following is a valid variable name?  

(a)   fred smith

(b)   123

(c)   12a

(d)   _num

Question 4.         

Fill in the following with Java data types

i

  

 

b

  

   

  

c

  

   

  

l

  

   

  

s

  

   

  

  

f

  

   

  

  

d

 

   

  

  

  

b

  

   

  

  

  

  

Question 5.         

The initial value held by a variable is undefined.

(a)   True

(b)   False  

Question 6.         

The data type for a number such as 7.318 is a  

(a)   long

(b)   int

(c)   float

(d)   String

Question 7.         

Both literals and constants have fixed values..

(a)   True

(b)   False  

Question 8.         

Which one of the following is a character literal?

(a)   'a'

(b)   "a" 

(c)    a

(d)   /a

Question 9.         

Which one of the following is a string literal?

(a)   'a'

(b)   "a" 

(c)    a

(d)   /a

Question 10.         

Class variables, instance variables, and local variables are the three classes of variables in Java.

(a)   True

(b)   False  

Question 11.         

Write down the keyword that declares a constant value that cannot be changed during program execution?

f___________

Question 12.         

Which one of the following is FALSE? 

(a)   all variables must be declared

(b)   all variables must be given a type when they are declared

(c)   the variables myData and MYdata are treated as the same variable by Java 

(d)   the variables myData and MYdata are treated as different variables by Java 

Question 13.         

Consider the following statement.

 

Car car = new Car("Mercedes Benz");

 

Which one of the following is false?  

(a)  car is the name of a class.

(b)  car is variable that references a Car object.

(c)  car is a class variable

(d)  car references an instance of the class Car

Question 14.         

Which one of the following is a valid declaration for a Java method that has an integer as a parameter and returns a String. 

(a)  public String myMethod(int n);

(b)  public myMethod(int n);

(c)  public myMethod String (int n);

(d)  String public myMethod(int n);

Question 15.         

Consider the following two methods (within the same class) 

public void main(String args[]){

int a=3;

String s = "Bluebirds";

a = birdWatch(a,s);

System.out.println("" + a + "" + s);

}

public int birdWatch(int a, String s){

a = a + 4;

s = "Blackbirds";

return a;  

}  

  What is printed?  

(a)  3 Bluebirds

(b)  7 Blackbirds

(c)  7 Bluebirds

(d)  3 Blackbirds  

        

 

  Site Home 

Java Home   

  Forum  

Course Info

Welcome

Overview

Assessment

Qualification

Scheme of Work

Assignments

Resources

Information

Blackboard

Learning Center

Web Materials

Reading

Java Demos

Utilities

Links

Lecture Materials

Tutorials & Notes

Exercises

Activities

Quizzes

 

Site Home

Top

Unit Home

ADR 2002