Midterm questions Flashcards
Normally the instance variables in a java class are given which access qualifier?
private
A data item that can only be used within in java method is called?
local variable
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?
a1 could be assigned to b1, but b1 could not be assigned to a1
What is the name of java mechanism for passing parameters to methods?
call by value
if the expression super.super.doit() appear in a method, this expression will cause a
Syntax error (“cause super is a key word”)
What is the best description for overriding method?
Method in a base class and derived class have the same signature and the return type
What is the best description for overloading method?
Two method in a class have the same name, but different numbers of parameters
All objects of the same class will have the ___ data members and the ___ methods
same, same
Java will automatically define a constructer for a class
If the programmer does not define any constructers for the class
Which two of the following statements about array are FALSE?
- 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
The acronym of JVM is ?
Java Virtual Machine
The five exceptions related java keyword are
- try
- catch
- throw
- throws
- finally
The number of simple numerical (int and floating point) data types in java is _____
6
- Int
- floating point
- long
- short
- double
- byte
The name of java data type whose maximum is 32767 is
short
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:
javadoc -d/ directory / SomeClass
Suppose you are preparing an executable jar file, in which the driver class is called someClass. Then your manifest file contains the line ____
Main-Class: SomeClass
In java, every class is descendant of the class named:
Object as a super class
The name of the only java package that you can use without explicitly import it, or any of the classes contained in it , is _____
java.lang.Object
The output of the substing System.out.println(“123456”.substring(2,4)); is
34
In java a ____ method is one which doesn’t have a body and it is meant to be overridden in every derived class
abstract methods
In java ____ contains headings for methods that must be defined by an implementing class
Interfaces
Any java block that you want to execute whether or not an exception is thrown should be placed within a ____ block
try
The value of the expression 6% 12 + 5/2 is ___
8
If expr1 and expr2 are both boolean expressions, the evaluation of expr2 in (expr1 || expr2) is not preformed if ____ and this called _____
expr1 is true , short circuit evaluation java
The output of the code String s = “oBaMa”;
s.toUpperCase();
System.out.println(s);
oBaMa - because it supposed to be like this
String c = “oBaMa”;
String d = c.toUpperCase();
System.out.println(d);
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:
exculpation
In UML class diagram, the symbol indicating that a method of the class private is ___
- (−), on the other hand, means it is private.
- (+) before an instance variable or method means the variable or method is public.
In the following very simple UML class diagram, draw an arrow to show that the class s inherits from class t
Just one arrow goes from S to T
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
immutable
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
equals
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 ____
this
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 _____
compareTo();
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
toString
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 \_\_\_\_
boxing, integer intObject(8);
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
m + n + i
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
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
Whats wrong with this code?
public class Practice {
private int n =0; public static void main(String[] args) { System.out.println("n = " + n); }
}
it wont run, because we either make fields static or your methods non-static.
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); }
}
it wont run, because; variable n might not have been initialized
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); } }
Nothing, works fine
What is the value of this one?
int n = 3;
int m = 4;
int result = n * (++m);
15
What is the value of this one?
int n = 3; int m = 4; int result = n * (m++);
12
What is the value of this one?
int n = 2; n++; System.out.println("n is " + n); n --; System.out.println("n is " + n);
n is 3
n is 2
As a boolean expression , what is this called? (temperature > 95) || (rainFall > 20) || (humidity >= 60)
short-circuit evaluation or lazy evaluation
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 _____
package , package
each file in a package has the following line at the start of the file:
package Package_Name;
The value of your _______ tells Java where to begin its search for a package,
class path variable
____ can help in dealing with name clashes; that is, they can help in handling situations in which two classes have the same name.
packages
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
JAR (Java Archive)
What does recursive method means?
It means a method calls itself
_____ 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.
Polymorphism