Midterm Reviewer Flashcards

1
Q

A component of a program that knows how to perform methods and interact with other objects.

A

Object

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

Does not occupy any memory space and is only a logical representation of data.

A

Class

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

How is an object created?

A

An object is created when a class is instantiated.

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

Java Virtual Machine executes much faster. To which Java characteristic does this pertain?

A

High-Performance

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

Complete date when JDK (Java Development Kit) 1.0 was released.

A

January 23, 1996

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

A reserved area in memory that holds a value which can be changed while the program is being executed

A

Variable

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

Created using defined constructors of classes and used to access objects.

A

Reference Data Types

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

A block of code similar to a method and is called when an instance of class is created.

A

Constructor

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

A collection of statements grouped together to perform an operation.

A

Method

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

A type of constructor wherein the signature is the same with the default constructor, but the body may have code/statements.

A

No-argument Constructor

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

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);
}
}

A

Error

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

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);
}
}

A

50w

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

Variables, methods and constructors which are declared public can be accessed by any class (True or False)

A

TRUE

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

Variables defined inside methods, constructors or blocks.

A

Class Variable

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

Keywords and identifiers can be used as variable names in Java (True or False)

A

FALSE

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

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);
    }
}
A

32

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

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

A

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

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);
    }
}
A

200

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

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] + " ");
    }
}
A

1 2 3

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

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));
    }
}
A

1

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

What is the output of the following code?

public class SampleClass {
final int number = 100;
public static void main(String[] args) {
System.out.println(“Number is “ + number);
}

}

22
Q

What is the output of the following code?

public class SampleClass {
public static void main(String[] args){

    boolean firstBool = true;
    boolean secondBool = true;

    if(b1 == b2){
        System.out.print("Domain");
    }

    if(b1.equals(b2)){
        System.out.print("Expansion");
    }
}

}

23
Q

What is the output of the following code?

public class SampleClass{

public static void main(String[] args) {
    
    byte firstByte = 150, secondByte = 30;
    byte thirdByte = firstByte / secondByte;        
    
    System.out.println("Result is " + thirdByte);
} }
24
Q

What is the output of the following code?

public class SampleClass{

public static void main(String[] args){            
    
    int try = 2;
    for(int count = 0; count < try; count++){
        System.out.print("Value of count is " + i + ". ");
    }        
}     }
25
What is the output of the following code? class PrintClass{ public PrintClass(double num){ System.out.print("First Constructor"); } public PrintClass(float num){ System.out.print("Second Constructor"); } } public class SampleClass{ public static void main(String[] args){ int longNum = 20; PrintClass pc = new PrintClass(longNum); } }
Second Constructor
26
What is the output of the following code? class CharCheckerClass{ public CharCheckerClass(int num){ System.out.print("Number Constructor"); } public CharCheckerClass(char charac){ System.out.print("Char Constructor"); } void CharCheckerClass(String string){ System.out.print("String Constructor"); } } public class SampleClass{ public static void main(String[] args){ String charac = "c"; CharCheckerClass one = new CharCheckerClass(charac); } }
ERROR
27
What is the output of the following code? class CheckerClass{ public CheckerClass(int i){ System.out.println("This is an integer."); } public void CheckerClass(short s){ System.out.println("This is a short."); } } public class SampleClass{ public static void main(String[] args){ short shorty = 100; CheckerClass one = new CheckerClass(shorty); } }
This is an integer.
28
What is the output of the following code? package ClassPackage; class FirstClass{ public FirstClass(){ System.out.print("One"); } } class SecondClass{ public SecondClass(){ System.out.print("Two"); } } class ThreeClass{ public ThreeClass(){ System.out.print("Three"); } } public class SampleClass{ static FirstClass first = new FirstClass(); SecondClass second = new SecondClass(); static ThreeClass third = new ThreeClass(); public static void main(String[] args) { System.out.print("Hello"); SampleClass sample = new SampleClass(); } }
OneThreeHelloTwo
29
What is the output of the following code? public class SampleClass{ public static void main(String[] args){ int number = 97; switch(number){ case 95 : System.out.print("First "); case 96 : System.out.print("Second "); case 'a' : System.out.print("Third "); case 'b' : System.out.print("Fourth "); case 'c' : System.out.print("Fifth "); } } }
Third Fourth Fifth
30
What is the output of the following code? public class SampleClass{ public static void main(String[] args){ int number1 = 0; while(number1 + 2 < 50){ number1 += 2; int number2 = 50; while(number2 - 2 > 0){ number2 -= 2; } } System.out.println(number1 + " " + number2); } }
Error
31
What is the output of the following code? public class SampleClass{ public static void main(String[] args){ int counter = 561; if(counter < 2000){ String stringy = "Lesser than the number."; }else{ String stringy = "Greater than the number."; } System.out.println(stringy); } }
ERROR
32
What is the output of the following code? class ObjectClass{ void ObjectClass(){ System.out.println("Instantiation complete."); } } public class SampleClass{ public static void main(String[] args){ ObjectClass one = new ObjectClass(); } }
No output
33
What is the output of the following code? public class SampleClass{ public static void main(String[] args){ for(int num1 = 0; num1 < 3; num1++){ for(int num2 = 0; num2 < 3; num2++){ if(num1 == num2) continue; System.out.print(num1 + " " + num2 + ", "); } } } }
0 1, 0 2, 1 0, 1 2, 2 0, 2 1,
34
What is the output of the following code? public class SampleClass{ public static void main(String[] args){ for(int number = 0 ; number < 5 ; number++) System.out.println(number + " "); System.out.println(number + " "); } }
ERROR
35
What is the output of the following code? public class SampleClass{ static String stringy = "false"; public static void main(String[] args) { if(stringy == false) System.out.println("Nothing to see here."); } }
ERROR
36
What is the output of the following code? class Hero { public void smash() { System.out.println("Detroit Smash!"); } } class Student extends Hero { private void smash() { System.out.println("Practice Smash!"); } } public class SampleClass { public static void main(String args[]) { Hero deku = new Student(); deku.smash(); } }
Compile-time Error
37
What is the output of the following code? class Hero { private void smash() { System.out.println("Detroit Smash!"); } } class Student extends Hero { public void smash() { System.out.println("Practice Smash!"); } } public class SampleClass { public static void main(String args[]) { Hero deku = new Student(); deku.smash(); } }
Compile-time Error
38
What is the output of the following code? class Kage { public void fight() { System.out.println("Flying Raijin!"); } } class Jonin extends Kage { public void fight() { System.out.println("Rasengan!"); } } class Shinobi extends Jonin { public void fight() { super.super.fight(); System.out.println("Shadow Clone Technique!"); } } public class SampleClass { public static void main(String[] args) { Shinobi ninja = new Shinobi(); ninja.fight(); } }
Compile-time Error
39
What is the output of the following code? class Kage { public void fight() { System.out.println("Flying Raijin!"); } } class Jonin extends Kage { public void fight() { System.out.println("Rasengan!"); } } class Shinobi extends Jonin { public void fight() { super.fight(); System.out.println("Shadow Clone Technique!"); } } public class SampleClass { public static void main(String[] args) { Shinobi ninja = new Shinobi(); ninja.fight(); } }
Rasengan! Shadow Clone Technique!
40
What is the output of the following code? final class DifficultClass { private final double num1; private final double num2; public DifficultClass(double num2, double num1) { this.num1 = num2; this.num2 = num1; } public String printLine() { return "" + num2 + " + " + num1 + "."; } } public class SampleClass { public static void main(String args[]) { DifficultClass c = new DifficultClass(150, 270); System.out.println("Numbers are " + c.printLine()); } }
Numbers are 270.0 + 150.0.
41
What is the output of the following code? class MoreDifficultClass { public MoreDifficultClass() { System.out.println("Let's make it challenging."); } public MoreDifficultClass(int num1) { System.out.println("Print Here!"); } } class DifficultClass extends MoreDifficultClass { private final double num1; private final double num2; public DifficultClass(double num2, double num1) { this.num1 = num2; this.num2 = num1; } public String printLine() { return "" + num2 + " + " + num1 + "."; } } public class SampleClass { public static void main(String args[]) { DifficultClass c = new DifficultClass(150, 270); System.out.println("Numbers are " + c.printLine()); } }
Let's make it challenging. Numbers are 270.0 + 150.0.
42
What is the output of the following code? class MoreDifficultClass { public MoreDifficultClass() { System.out.println("Let's make it challenging."); } public MoreDifficultClass(int num1) { System.out.println("Print Here!"); } } class DifficultClass extends MoreDifficultClass { private final double num1; private final double num2; public DifficultClass(double num2, double num1) { this.num1 = num2; this.num2 = num1; } public String printLine() { return "" + num2 + " + " + num1 + "."; } } public class SampleClass { public static void main(String args[]) { DifficultClass c = new MoreDifficultClass(150); System.out.println("Numbers are " + c.printLine()); } }
Compile-time Error
43
What is the output of the following code? class MoreDifficultClass { public MoreDifficultClass() { System.out.println("Let's make it challenging."); } public MoreDifficultClass(int num1) { System.out.println("Print Here!"); } public String printLine() { return "Successful printing!"; } } class DifficultClass extends MoreDifficultClass { private final double num1; private final double num2; public DifficultClass() { num1 = 340; num2 = 580; System.out.println("Printing Hatdog!"); } public DifficultClass(double num2, double num1) { this.num1 = num2; this.num2 = num1; } public String printLine() { return "" + num2 + " + " + num1 + "."; } } public class SampleClass { public static void main(String args[]) { MoreDifficultClass c = new DifficultClass(); System.out.println("Numbers are " + c.printLine()); } }
Let's make it challenging. Printing Hatdog! Numbers are 580.0 + 340.0.
44
What is the output of the following code? class Jujutsu { int showJujutsu(int num) { num /= 50; return num; } } class SpecialGrade extends Jujutsu { int showSorcerer(int num) { num *= 10; return showJujutsu(num); } } public class SampleClass { public static void main(String[] args) { SpecialGrade gojo = new SpecialGrade(); System.out.println(gojo.showSorcerer(500)); } }
100
45
What is the output of the following code? class Resource { String resourceName = ""; float resourceSalary = 0; public void printSalary() { resourceSalary += 10000; System.out.println("Salary is " + resourceSalary); } } class Analyst extends Resource { public void printSalary() { resourceSalary += 30000; System.out.println("Salary is " + resourceSalary); } } public class SampleClass { public static void main(String[] args) { Resource s = new Resource(); Analyst a = new Analyst(); Resource res = new Analyst(); s.printSalary(); a.printSalary(); res.printSalary(); } }
Salary is 10000.0 Salary is 30000.0 Salary is 30000.0
46
What is the output of the following code? class Resource { String resourceName = ""; float resourceSalary = 0; public void printSalary() { resourceSalary += 10000; System.out.println("Salary is " + resourceSalary); } } class Analyst extends Resource { public void printSalary() { resourceSalary += 30000; System.out.println("Salary is " + resourceSalary); } } public class SampleClass { public static void main(String[] args) { Resource s = new Resource(); Analyst a = new Analyst(); Analyst ana = new Resource(); s.printSalary(); a.printSalary(); ana.printSalary(); } }
Compile-time Error
47
What is the output of the following code? class Resource { String resourceName = ""; float resourceSalary = 0; public void printSalary() { System.out.println("Salary is " + resourceSalary); } public void printSalary(float resourceName) { this.resourceSalary = resourceName; System.out.println("Salary is " + resourceSalary); } public void printSalary(String resourceName, float resourceSalary) { this.resourceName = resourceName; this.resourceSalary = resourceSalary; System.out.println("Salary is " + resourceSalary); } } class Analyst extends Resource { public void printSalary() { resourceSalary += 30000; System.out.println("Salary is " + resourceSalary); } } public class SampleClass { public static void main(String[] args) { Analyst a = new Analyst(); a.printSalary("All Might", 10000); a.printSalary(); a.printSalary(19000); } }
Salary is 10000.0 Salary is 40000.0 Salary is 19000.0
48
What is the output of the following code? class Resource { String resourceName = ""; float resourceSalary = 0; public void printSalary() { System.out.println("Salary is " + resourceSalary); } public void printSalary(float resourceName) { this.resourceSalary = resourceName; System.out.println("Salary is " + resourceSalary); } public void printSalary(String resourceName, float resourceSalary) { this.resourceName = resourceName; this.resourceSalary = resourceSalary; System.out.println("Salary is " + resourceSalary); } } class Analyst extends Resource { public void printSalary() { resourceSalary += 30000; System.out.println("Salary is " + resourceSalary); } } public class SampleClass { public static void main(String[] args) { Analyst a = new Resource(); a.printSalary("All Might", 10000); a.printSalary(); a.printSalary(19000); } }
Compile-time Error
49
What is the output of the following code? class Resource { String resourceName = ""; float resourceSalary = 0; public void printSalary() { System.out.println("Salary is " + resourceSalary); } public void printSalary(float resourceName) { this.resourceSalary = resourceName; System.out.println("Salary is " + resourceSalary); } public void printSalary(String resourceName, float resourceSalary) { this.resourceName = resourceName; this.resourceSalary = resourceSalary; System.out.println("Salary is " + resourceSalary); } } class Analyst extends Resource { public void printSalary() { resourceSalary += 30000; System.out.println("Salary is " + resourceSalary); } } public class SampleClass { public static void main(String[] args) { Resource a = new Analyst(); a.printSalary("All Might", 10000); a.printSalary(); a.printSalary(19000); } }
Salary is 10000.0 Salary is 40000.0 Salary is 19000.0
50
What is the output of the following code? import java.util.ArrayList; public class SampleClass { public static void main(String[] args) { Integer i = new Integer(3000); int num1 = i.intValue(); int num2 = i; ArrayList numbers = new ArrayList(); numbers.add(num1); numbers.add(num2); for(Integer integer: numbers) { System.out.print(integer); } } }
30003000