Midterm Reviewer Flashcards
A component of a program that knows how to perform methods and interact with other objects.
Object
Does not occupy any memory space and is only a logical representation of data.
Class
How is an object created?
An object is created when a class is instantiated.
Java Virtual Machine executes much faster. To which Java characteristic does this pertain?
High-Performance
Complete date when JDK (Java Development Kit) 1.0 was released.
January 23, 1996
A reserved area in memory that holds a value which can be changed while the program is being executed
Variable
Created using defined constructors of classes and used to access objects.
Reference Data Types
A block of code similar to a method and is called when an instance of class is created.
Constructor
A collection of statements grouped together to perform an operation.
Method
A type of constructor wherein the signature is the same with the default constructor, but the body may have code/statements.
No-argument Constructor
What is the output of the following code?
public class MainClass {
public static void main(String[] args) {
char letter = 65;
System.out.println(“Letter is “ + letter);
}
}
Error
What is the output of the following code?
public class MainClass {
public static void main(String[] args) {
int number= 50;
char letter= ‘w’;
System.out.print(number);
System.out.print(letter);
}
}
50w
Variables, methods and constructors which are declared public can be accessed by any class (True or False)
TRUE
Variables defined inside methods, constructors or blocks.
Class Variable
Keywords and identifiers can be used as variable names in Java (True or False)
FALSE
What is the output of the following code?
public class SampleClass { public static void main(String args[]) { int g = 3; System.out.print(++g * 8); } }
32
Which of the following is not a use of the this keyword in Java?
A. Passing itself to the method of the same class.
B. Passing itself to another method.
C. Referring to the instance variable when a local variable has the same name.
D. Calling another constructor in constructor chaining
A
What is the output of the following code?
public class Square { int width; int height; int length; } public class MainClass { public static void main(String args[]) { Square s = new Square(); s.width = 10; s.height = 2; s.length = 10; int box = obj.width * obj.height * obj.length; System.out.print(box); } }
200
What is the output of the following code?
public class MainClass { public static void main(String args[]) { int series[] = {1, 2, 3, 4, 5}; for ( int num = 0; num < series.length - 2; ++num) System.out.println(series[num] + " "); } }
1 2 3
What is the output of the following code?
public class RecurClass { int recur(int num) { int result = 0; if (num == 1) return 1; result = recur(num - 1); return result; } } public class MainClass { public static void main(String args[]) { RecurClass r = new RecurClass() ; System.out.print(r.recur(10)); } }
1