Midterm questions Flashcards

1
Q

Normally the instance variables in a java class are given which access qualifier?

A

private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A data item that can only be used within in java method is called?

A

local variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

suppose that java class A inherits from Class B, and suppose a1 and b1 refer to objects of class A and B. Which one of the options is true?

A

a1 could be assigned to b1, but b1 could not be assigned to a1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the name of java mechanism for passing parameters to methods?

A

call by value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

if the expression super.super.doit() appear in a method, this expression will cause a

A

Syntax error (“cause super is a key word”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the best description for overriding method?

A

Method in a base class and derived class have the same signature and the return type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the best description for overloading method?

A

Two method in a class have the same name, but different numbers of parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

All objects of the same class will have the ___ data members and the ___ methods

A

same, same

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Java will automatically define a constructer for a class

A

If the programmer does not define any constructers for the class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which two of the following statements about array are FALSE?

A
  • You can get the size of the array by using its length () method
  • The size of an array can be changed after it has been created
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The acronym of JVM is ?

A

Java Virtual Machine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The five exceptions related java keyword are

A
  • try
  • catch
  • throw
  • throws
  • finally
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The number of simple numerical (int and floating point) data types in java is _____

A

6

  • Int
  • floating point
  • long
  • short
  • double
  • byte
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The name of java data type whose maximum is 32767 is

A

short

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Suppose you have the source code for a class called SomeClass in an named file and you have a command window open on the directory containing that file. Assume the file also contains the appropriate comments. Give the simplest command that will create HTML documentation for just this class and place that in a subdirectory called mydoes in the current directory:

A

javadoc -d/ directory / SomeClass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Suppose you are preparing an executable jar file, in which the driver class is called someClass. Then your manifest file contains the line ____

A

Main-Class: SomeClass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

In java, every class is descendant of the class named:

A

Object as a super class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

The name of the only java package that you can use without explicitly import it, or any of the classes contained in it , is _____

A

java.lang.Object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The output of the substing System.out.println(“123456”.substring(2,4)); is

A

34

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

In java a ____ method is one which doesn’t have a body and it is meant to be overridden in every derived class

A

abstract methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

In java ____ contains headings for methods that must be defined by an implementing class

A

Interfaces

22
Q

Any java block that you want to execute whether or not an exception is thrown should be placed within a ____ block

A

try

23
Q

The value of the expression 6% 12 + 5/2 is ___

A

8

24
Q

If expr1 and expr2 are both boolean expressions, the evaluation of expr2 in (expr1 || expr2) is not preformed if ____ and this called _____

A

expr1 is true , short circuit evaluation java

25
Q

The output of the code String s = “oBaMa”;
s.toUpperCase();
System.out.println(s);

A

oBaMa - because it supposed to be like this
String c = “oBaMa”;
String d = c.toUpperCase();
System.out.println(d);

26
Q

The fact that we can describe categories of objects using classes, which combine both the attributes and the behaviours that are shared by all the objects of a given category is one of the three key OOB and is called:

A

exculpation

27
Q

In UML class diagram, the symbol indicating that a method of the class private is ___

A
  • (−), on the other hand, means it is private.

- (+) before an instance variable or method means the variable or method is public.

28
Q

In the following very simple UML class diagram, draw an arrow to show that the class s inherits from class t

A

Just one arrow goes from S to T

29
Q

In java once an object of type String has been created, that object cant be changed, which we describe by saying that the java strings are

A

immutable

30
Q

IF you have written a java class and want users of your class to be able to test whether two objects of that class have the same properties, then you must override, the ___ method

A

equals

31
Q

Java has a keyword that is convenient to employ when you want to use a parameters to have the same name as the private data members. The keyword is ____

A

this

32
Q

If you are writing a Java class and you want that class to implement the Comparable interface, then the only method your class must implement to do this is the _____

A

compareTo();

33
Q

if myObj is a java object reference variable for an object of any class, you can always execute the statement System.out.println(myObj); , because this causes the ____ method to be invoked on myObj, and that method is always present

A

toString

34
Q
If you want to create an object of the wrapper class integer containing the value 8, you can do this:
integer intObject = new Integer(8); , but this is no longer necessary, because a new feature called \_\_\_\_\_  was added in java 5, and now to accomplish the sam thing as the above line, you can just use the following shortcut \_\_\_\_
A

boxing, integer intObject(8);

35
Q

Give an expression involving m and n whose value is the number of times Hello is printed by the for loop shown as for(int i = m; i > =n; i–)
System.out.println(“Hello”); assue m > n

A

m + n + i

36
Q

Show on the line below what order the values 29 20 37 18 31 22 33 will have after the third pass of the outer loop has completed, when our version of the selection sort algorithm is applied

A

18 20 22 29 31 37 33
18 20 22 29 31 37 33
18 20 22 29 31 37 33
18 20 22 29 31 37 33

37
Q

Whats wrong with this code?

public class Practice {

private int n =0;
public static void main(String[] args) {

    System.out.println("n = " + n);
}

}

A

it wont run, because we either make fields static or your methods non-static.

38
Q

Whats wrong with this code?

public class Practice {

private static int n =0;
public static void main(String[] args) {

    int n;
    System.out.println("n = " + n);
}

}

A

it wont run, because; variable n might not have been initialized

39
Q

Whats wrong with this code?

public class Practice {

int n;
public static void main(String[] args) {
        Car car = new Car();
        car.getModel();
        }
        private void getModel() {
            System.out.println("n = " + n);
        }
}
A

Nothing, works fine

40
Q

What is the value of this one?

int n = 3;
int m = 4;
int result = n * (++m);

A

15

41
Q

What is the value of this one?

    int n = 3;
    int m = 4;
    int result = n * (m++);
A

12

42
Q

What is the value of this one?

 int n = 2;
        n++;
        System.out.println("n is " + n);
        n --;
        System.out.println("n is " + n);
A

n is 3

n is 2

43
Q

As a boolean expression , what is this called? (temperature > 95) || (rainFall > 20) || (humidity >= 60)

A

short-circuit evaluation or lazy evaluation

44
Q

A _____ is simply a collection of classes that have been grouped together into a folder and the name of the folder is the name of the _____

A

package , package

45
Q

each file in a package has the following line at the start of the file:

A

package Package_Name;

46
Q

The value of your _______ tells Java where to begin its search for a package,

A

class path variable

47
Q

____ can help in dealing with name clashes; that is, they can help in handling situations in which two classes have the same name.

A

packages

48
Q

A ____ is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution

A

JAR (Java Archive)

49
Q

What does recursive method means?

A

It means a method calls itself

50
Q

_____ allows you to make changes in the method definition for the derived classes and have those changes apply to the methods written in the base class.

A

Polymorphism