OBJECT-ORIENTED PROGRAMMING Flashcards

1
Q

A string is enclosed with single quotation marks.

A

False

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

One of the tools for Object oriented design includes class hierarchy diagram

A

True

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

Netbeans started as a student project called Selfie

A

False

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

All methods and variables in Java language are kept inside a method?

A

False

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

James Gosling works for ____________ when they developed java?

A

Sun Microsystems

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

Scanner class is found on java.io package.

A

false

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

byte has a maximum value of 127

A

True

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

int has a width of _ bytes

A

4

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

float has a width of _ bytes

A

8

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

println does not belong to the System class.

A

False

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

A Netbeans feature that provides information about the runtime behavior of applications

A

NetBeans Profiler

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

The main method is declared public so that it is accessible as part of the public interface of the program.

A

True

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

The goal in developing netbeans was to write a Delphi- like Java IDE in Java for the first time.

A

True

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

Most IDEs today doesn’t have GUI modeling utilities that simplify the development of UIs.

A

false

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

A valid Identifier or name in Java language can start with which character?

A

option1: a-z, A-Z
option2: $, _

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

The System keyword defines a template for an object of derived type HelloWorld

A

False

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

It is a derived data type

A

String

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

Scanner class is found on what java package?

A

java.util

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

In standalone Java applications, which method is mandatory?

A

main method

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

A java edition that provides a robust, flexible environment for applications running on embedded and mobile devices in the Internet of Things

A

Micro Edition

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

API stands for

A

Application Programming Interface

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

All methods and variables in Java language are kept inside a?

A

Class or Interface

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

A feature of Netbeans that makes it easy to create, deploy and import java beans.

A

Enterprise Java Beans (EJB) Development

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

boolean data type has only two values

A

true

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

IDE stands for ______

A

Integrated Development Environment

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

The __________ creates a software simulation of a CPU and memory and handles all communication between the Java program and the underlying operating system and hardware.

A

JVM

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

A documentation or javadoc comment is enclosed between /* and **/

A

False

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

double data type has a width of _ in bytes.

A

8

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

What is the need to mention “static” before main method?

A

Option1 : To call main method without creating an object of class

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

short has a width of _ bytes

A

4

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

It returns the long value of the number that the next token represents.

A

NextLng()

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

It is a computer software to help computer programmers develop software.

A

Integrated Development Environment (IDE)

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

print() prints string inside the quotes then the cursor moves to the beginning of the next line

A

False

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

Sun Microsystems is now a subsidiary of Cisco Corporation?

A

False. Oracle

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

A feature of Netbeans that enables support for multiple source roots, easy management of libraries, easily ported to other environments, all based on Apache Ant.

A

project system

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

It reads a float value from the user.

A

nextFloat()

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

main method is void because the Java interpreter does not expect to receive or process any output from the class.

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

A feature of Netbeans for renaming, changing and moving of various objects, field encapsulation and usage finding.

A

Refactoring

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

An operator that copies a bit to the result if it exists in both operands.

A

& (bitwise AND)

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

They return the result of shifting the bits of the left operand by the number of positions specified by the right operand.

A

Supposed: double x = 13.1614; int y = (int)x; what is the value of y?

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

Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.

A

>

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

What are the legal indexes for the array ar, given the following declaration:

int[] ar = {2, 4, 6, 8 }

A

0, 1, 2, 3

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

What is the output of the following code fragments?

int [ ] fun = new int [5];

fun[0] = 1;

fun[1] = 2;

fun[2] = 3;

fun[3] = 4;

fun[4] = 5;

int j = 3;

System.out.println(fun[ j-1]) ;

A

3

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

What is the output of the following code fragment?

for ( int j = 10; j > 5; j– )
{
System.out.print( j + “ “ );
}
System.out.println( );

A

10 9 8 7 6

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

What will be the output of the following program?

public class AllDimensionArrays {

public static void main(String[] args) {

int[] a1d = {};

int[] b1d = {1, 3};

int[][] a2d = {};

int[][] b2d = {{}};

int[][] c2d = {{1, 2}, {5}};

System.out.print(a1d.length + “ “ + b1d.length + “ “);

System.out.print(a2d.length + “ “ + a2d[0].length + “ “ + b2d.length + “ “ + b2d[0].length + “ “);

System.out.print(c2d.length + “ “ + c2d[0].length + “ “ + c2d[1].length);

}

}

A

ArrayIndexOutOfBoundsException

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

Consider the following codes:

int x=4;

System.out.println(–x);

What will be the EXACT output?

A

3

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

Checks if the values of two operands are equal or not, if values are not equal then condition becomes true.

A

!=

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

The break statement causes the program flow to exit prematurely from the body of the loop statement.

A

true

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

What is the result of 7%2

A

1

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

decrease the value of the variable by a particular number by which it was decreased

A

decrement operators

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

An operator that divides left-hand operand by right-hand operand and returns remainder.

A

%

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

What will be the output of the following program?

    boolean lampX = false, result;

    boolean lampY = true;

    result = lampY || lampX;

    System.out.println("Lamp switch-on " + result);

    result = lampY | lampX;

    System.out.println("Lamp switch-on " + result);
A

Lamp switch-on true
Lamp switch-on true

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

What will be the output of the following program?

class ArrayOutput
{
public static void main(String args[])
{
int[] input = {3, 5, 6, 7};
int output = multiplyEveryElement(input);
System.out.print(“Result of multiplying every element = “ + output + “.”);
}

public static int multiplyEveryElement(int[] input)
{
    int args = 1;

    for(int i = 0; i <= input.length - 1; i++)
    {
        args *= input[i];
    }
    return args;
} }
A

Result of multiplying every element = 630.

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

Consider the following codes:

int x=2;

System.out.println(–x);

What will be the EXACT output?

A

1

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

Dividing integer by zero results in the throwing of ____________

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

The do-while loop facilitates evaluation of condition or expression at the end of the loop to ensure that the statements are executed at least once

A

True

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

bitwise operator is an operator used to perform bitwise operations on bit patterns or binary numerals that involve the manipulation of individual bits

A

True

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

Method overriding is combination of inheritance and polymorphism?

A

True

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

Which of the following is a type of polymorphism in Java?

A

Compile time polymorphism

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

The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines

A

true

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

Procedural Programming is a technique of solving a problem and breaking it down into smaller parts and solving each of the smaller problems.

A

true

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

When Overloading does not occur?

A

More than one method with same name but different method signature and different number or type of parameters

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

final Class: a class that can never be sub-classed

A

true

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

this keyword can be passed as argument in the constructor call.

65
Q

It represents an instance of the class in which it appears

66
Q

final Variable: constant variable

67
Q

variables used in a method

A

method variables

68
Q

In Encapsulation, Class variables can be made read-only or write-only

69
Q

Encapsulation is also called as?

A

Data Hiding

70
Q

Which among the following best describes encapsulation?

A

It is a way of combining various data members and member functions that operate on those data members into a single unit

71
Q

In Encapsulation, the programmer can change one part of the code without affecting other parts

72
Q

If data members are private, what can we do to access them from the class object?

A

Create public member functions to access those data members

73
Q

Which among the following is false for single level inheritance?

A

There can be more than 2 independent classes involved in single inheritance

74
Q

The private member’s are made public to all the classes in inheritance.

75
Q

How many classes can be inherited by a single class in java?

76
Q

Which is the correct syntax of inheritance?

A

class derived_classname : access base_classname{ /define class body/ };

77
Q

All languages support single level inheritance

78
Q

An abstract class declares a common interface for the various members of a class hierarchy. The abstract class contains methods that will be declared in the subclasses. All classes in the hierarchy can use this same set of methods through polymorphism.

79
Q

Which among the following best describes polymorphism?

A

It is the ability for a message/data to be processed in more than one form

80
Q

In case of using abstract class or function overloading, which function is supposed to be called first?

A

Function with highest priority in compiler

81
Q

Which type of function among the following shows polymorphism?

A

Virtual function

82
Q

All methods in a final class must be explicitly declared final.

83
Q

Which of the following is FALSE about abstract classes in Java

A

A class can inherit from multiple abstract classes.

84
Q

Abstraction principle includes

A

Use abstraction whenever possible to avoid duplication

85
Q

Can an abstract class define both abstract methods and non-abstract methods?

A

Yes–the child classes inherit both.

86
Q

In order for the following code to be correct, what must be the type of the reference variable card?

_________ card;

card = new Valentine( “Joe”, 14 ) ;

card.greeting();

card = new Holiday( “Bob” ) ;

card.greeting();

card = new Birthday( “Emily”, 12 ) ;

card.greeting();

87
Q

Which class is used to handle the input and output exceptions?

A

IOExceptions

88
Q

Say that methodA calls methodB, and methodB calls methodC. MethodC might throw a NumberFormatException. Can the program be written so that methodA handles the exception?

A

Yes, if the headers for methodC and methodB say …throws NumberFormatException

89
Q

Say that a method catches an IOException in a catch{} block. Is it possible for that block to do some processing and then throw the same exception to the caller?

A

Yes—as long as the method also has a throws clause for that exception.

90
Q

class Base extends Exception {}

class Derived extends Base {}

public class Main {

public static void main(String args[]) {

// some other stuff

try {

   // Some monitored code

   throw new Derived();

}

catch(Base b)     {

   System.out.println("Caught base class exception");

}

catch(Derived d)  {

   System.out.println("Caught derived class exception");

}

}

}

A

Compiler Error because base class exception is caught before derived class

91
Q

You are writing a program to check people into a hotel. People over 65 get a 10% discount. How would you write the program?

A

Normal if-else programming logic will be used.

92
Q

If the Java program is using assertions, it must be run with -ea or -enableassertions switches.

93
Q

public class Test

{

public void foo() 

{

    assert false; /* Line 5 */

    assert false; /* Line 6 */

} 

public void bar()

{

    while(true)

    {

        assert false; /* Line 12 */

    } 

    assert false;  /* Line 14 */

} 

}

What causes compilation to fail?

94
Q

What will happen when you compile and run the following code with assertion enabled?

public class Test{

        public static void main(String[] args){

                    displayAge(20);

        }

       

        private static void displayAge(int age){                     

                    assert age >= 21 : getAgeMessage();

                    System.out.println(age);                                

        }

 

        private static String getAgeMessage() {

                    return "Your age must be greater than 21";

        }

}

A

The code will compile but will throw AssertionError when executed

95
Q

Here is a method definition: int compute( a int, y double ){ . . . .} Which of the following has a different signature?

A

int compute( a int, y int ){ . . . .}

96
Q

In case of using abstract class or function overloading, which function is supposed to be called first?

A

Function with highest priority in compiler

97
Q

It is the ability for a message/data to be processed in more than one form

A

polymorphism

98
Q

A method that is declared final cannot be overridden in a subclass.

99
Q

An interface is typically used in place of an abstract class when there is no default implementation to inherit.

100
Q

Higher the level of abstraction, higher are the details.

101
Q

Is one without a body that is declared with the reserved word abstract.

A

abstract method

102
Q

Which of the following classes fail to compile?

abstract class X { abstract void method(); }

abstract class Y extends X { }

class Z extends Y { void method() { System.out.println(“Class Z”); } }

A

All classes compile

103
Q

Encapsulation and abstraction differ as ____________

A

Binding and Hiding respectively

104
Q

MethodX might encounter an IOException or an AWTException, but handles neither. How should the header for methodX be written?

A

… methodX(…) throws IOException, AWTException

105
Q

Which are the two blocks that are used to check error and handle the error?

A

Try and catch

106
Q

What method of an Exception object returns a message string?

A

getMessage()

107
Q

Which three statements are true?

Option1: Assertion checking is typically enabled when a program is deployed.

Option2:It is never appropriate to write code to handle failure of an assert statement.

Option3:Assertion checking is typically enabled during program development and testing.

Option4:Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis.

Option5:Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.

108
Q

What handles interface handle sequences?

109
Q

What package contain all the collection classes?

110
Q

What List class is synchronized?

111
Q

You can’t put null elements into Queues in the API?

112
Q

Can we have a sorted and unordered set?

113
Q

What type of collection does not extend the Collection interface?

114
Q

What is the difference between HashSet and TreeSet?

A

HashSet maintains no order while TreeSet maintains ascending order.

115
Q

The erase() method of OutputStream Class flushes the current output stream.

116
Q

This the standard output stream.

A

System.out

117
Q

What is the difference between HashMap and Hashtable?

A

HashMap is not synchronized while the Hashtable is synchronized.

118
Q

The standard error stream.

A

system.err

119
Q

All are invalid codes in getting an input from the console, except one.
i=System.in.readln(123);
i=System.in.readf(“%i”,123);
i=System.in.read=123;
i=System.in.read();

A

i=System.in.read();

120
Q

is the constructor of the FileReader class that creates a new file and get its file name in stringT

A

The FileReader (String file)

121
Q

A method of the FileWriter class that flushes the data of FileWriter.

122
Q

A constructor of the FileReader class that creates a new file and get its file name in string

A

FileReader (String file)

123
Q

What class returns data in byte format like FileInputStream class?

A

Java FileReader

124
Q

A method of the FileWriter class that is used to write the string into FileWriter.

A

write (String text)

125
Q

A method of the FileReader class that is used to return a character in ASCII form. It returns -1 at the end of file.

126
Q

the constructor of the FileReader class that creates a new file and get its file name in file objects.

A

FileReader (File file)

127
Q

A method of the FileWriter class that is used to write char array into FileWriter.

A

write (char[] c)

128
Q

a sequence of data.

129
Q

It is the superclass of all classes representing an output stream of bytes. It accepts output bytes and sends them to some sink.

A

OutputStream

130
Q

the standard input stream.

131
Q

What is the design pattern followed by Iterator?

A

Iterator design pattern

132
Q

What interface is not a part of Java’s collection framework?

A

SortedList

133
Q

What is the correct difference between ArrayList and LinkedList?

A

ArrayList uses a dynamic array whereas the LinkedList uses doubly linked list.

134
Q

Which List would you use if wanted fast access and were doing lots of insertions and deletions?

A

LinkedList

135
Q

What is the method to convert the array of strings into a list?

A

Arrays class asList() method

136
Q

What is returned from both the compare() and compareTo() methods?

137
Q

Which List would you use if wanted fast access and were doing lots of insertions and deletions?

A

LinkedList

138
Q

What type of Queue is a PriorityQueue?

139
Q

What do maps care about

A

Uniqueness

140
Q

What is the difference between the Iterator and Enumeration?

A

Iterator can traverse legacy and non-legacy containers whereas the Enumeration can traverse only legacy containers.

141
Q

What type of collection would we use if we wanted no duplicates?

142
Q

is used to process the input and produce the output.

A

Java I/O (Input and Output)

143
Q

Automatically created streams are attached with the console.

144
Q

is used to read data from a source; it may be a file, an array, peripheral device

A

InputStream

145
Q

In using __________, unlike FileOutputStream class, you don’t need to convert string into byte array because it provides method to write string directly.

A

FileWriter class

146
Q

is used to read data from the file.

A

Java FileReader class

147
Q

the constructor of the FileReader class that creates a new file and get its file name in string

A

ReaderFile (String file)

148
Q

Java language is originally called ______

A

the ‘Oak’

149
Q

a general-purpose, concurrent, class-based, object-
oriented language that is specifically designed to have as few
implementation dependencies as possible.

150
Q

They are compiled into a format called bytecode (files with .class
extension), which can be executed by a Java interpreter.

A

The Java source code files (files with .java extension)

151
Q

It was intended for use in Sun’s project research to work on a
programming software to control electronic devices.

152
Q

This defines a class, a template for an object of derived type
HelloWorld

A

class HelloWorld

153
Q

This access specifier/modifier, the main method is declared public so that it is accessible as part of the public interface of the program. Fundamentals of Java Language

154
Q

This is the state of the method, it is static
because it must be called before the class
that hosts the method is instantiated

155
Q

It returns _______ This is because the Java
interpreter does not expect to receive or
process any output from the class.

156
Q

This is one of dozens of methods in the Systemclass. The System class is a part of the core Java language package of the Application
Programming Interface (API)

A

System.out.println( )

157
Q

These names that are given by the
programmer as name of variables, methods
or functions, classes etc.

Rules:
Each character is either a digit, letter, underscore or currency symbol.
First character cannot be a digit.
The identifier name must not be a reserved word.

A

Identifiers

158
Q

three (3) types of Java Comments

A
  1. A single-line comment starting with //
  2. A multi-line comment enclosed within /* */
  3. A documentation or javadoc comment is
    enclosed between /** and */. These
    comments can be used to generate HTML
    documents using the javadoc utility, which is
    part of Java language comment.