OBJECT-ORIENTED PROGRAMMING Flashcards

(158 cards)

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
IDE stands for ______
Integrated Development Environment
26
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.
JVM
27
A documentation or javadoc comment is enclosed between /* and **/
False
28
double data type has a width of _ in bytes.
8
29
What is the need to mention "static" before main method?
Option1 : To call main method without creating an object of class
30
short has a width of _ bytes
4
31
It returns the long value of the number that the next token represents.
NextLng()
32
It is a computer software to help computer programmers develop software.
Integrated Development Environment (IDE)
33
print() prints string inside the quotes then the cursor moves to the beginning of the next line
False
34
Sun Microsystems is now a subsidiary of Cisco Corporation?
False. Oracle
35
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.
project system
36
It reads a float value from the user.
nextFloat()
37
main method is void because the Java interpreter does not expect to receive or process any output from the class.
38
A feature of Netbeans for renaming, changing and moving of various objects, field encapsulation and usage finding.
Refactoring
39
An operator that copies a bit to the result if it exists in both operands.
& (bitwise AND)
40
They return the result of shifting the bits of the left operand by the number of positions specified by the right operand.
Supposed: double x = 13.1614; int y = (int)x; what is the value of y?
41
Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.
>
42
What are the legal indexes for the array ar, given the following declaration: int[] ar = {2, 4, 6, 8 }
0, 1, 2, 3
43
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]) ;
3
44
What is the output of the following code fragment? for ( int j = 10; j > 5; j-- ) { System.out.print( j + " " ); } System.out.println( );
10 9 8 7 6
45
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); } }
ArrayIndexOutOfBoundsException
46
Consider the following codes: int x=4; System.out.println(--x); What will be the EXACT output?
3
47
Checks if the values of two operands are equal or not, if values are not equal then condition becomes true.
!=
48
The break statement causes the program flow to exit prematurely from the body of the loop statement.
true
49
What is the result of 7%2
1
50
decrease the value of the variable by a particular number by which it was decreased
decrement operators
51
An operator that divides left-hand operand by right-hand operand and returns remainder.
%
52
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);
Lamp switch-on true Lamp switch-on true
53
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; } }
Result of multiplying every element = 630.
54
Consider the following codes: int x=2; System.out.println(--x); What will be the EXACT output?
1
55
Dividing integer by zero results in the throwing of ____________
56
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
True
57
bitwise operator is an operator used to perform bitwise operations on bit patterns or binary numerals that involve the manipulation of individual bits
True
58
Method overriding is combination of inheritance and polymorphism?
True
59
Which of the following is a type of polymorphism in Java?
Compile time polymorphism
60
The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines
true
61
Procedural Programming is a technique of solving a problem and breaking it down into smaller parts and solving each of the smaller problems.
true
62
When Overloading does not occur?
More than one method with same name but different method signature and different number or type of parameters
63
final Class: a class that can never be sub-classed
true
64
this keyword can be passed as argument in the constructor call.
false
65
It represents an instance of the class in which it appears
this
66
final Variable: constant variable
true
67
variables used in a method
method variables
68
In Encapsulation, Class variables can be made read-only or write-only
True
69
Encapsulation is also called as?
Data Hiding
70
Which among the following best describes encapsulation?
It is a way of combining various data members and member functions that operate on those data members into a single unit
71
In Encapsulation, the programmer can change one part of the code without affecting other parts
true
72
If data members are private, what can we do to access them from the class object?
Create public member functions to access those data members
73
Which among the following is false for single level inheritance?
There can be more than 2 independent classes involved in single inheritance
74
The private member's are made public to all the classes in inheritance.
False
75
How many classes can be inherited by a single class in java?
Only 1
76
Which is the correct syntax of inheritance?
class derived_classname : access base_classname{ /*define class body*/ };
77
All languages support single level inheritance
True
78
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.
true
79
Which among the following best describes polymorphism?
It is the ability for a message/data to be processed in more than one form
80
In case of using abstract class or function overloading, which function is supposed to be called first?
Function with highest priority in compiler
81
Which type of function among the following shows polymorphism?
Virtual function
82
All methods in a final class must be explicitly declared final.
false
83
Which of the following is FALSE about abstract classes in Java
A class can inherit from multiple abstract classes.
84
Abstraction principle includes
Use abstraction whenever possible to avoid duplication
85
Can an abstract class define both abstract methods and non-abstract methods?
Yes--the child classes inherit both.
86
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();
Card
87
Which class is used to handle the input and output exceptions?
IOExceptions
88
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?
Yes, if the headers for methodC and methodB say ...throws NumberFormatException
89
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?
Yes---as long as the method also has a throws clause for that exception.
90
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"); } } }
Compiler Error because base class exception is caught before derived class
91
You are writing a program to check people into a hotel. People over 65 get a 10% discount. How would you write the program?
Normal if-else programming logic will be used.
92
If the Java program is using assertions, it must be run with -ea or -enableassertions switches.
False
93
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?
Line 14
94
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"; } }
The code will compile but will throw AssertionError when executed
95
Here is a method definition: int compute( a int, y double ){ . . . .} Which of the following has a different signature?
int compute( a int, y int ){ . . . .}
96
In case of using abstract class or function overloading, which function is supposed to be called first?
Function with highest priority in compiler
97
It is the ability for a message/data to be processed in more than one form
polymorphism
98
A method that is declared final cannot be overridden in a subclass.
true
99
An interface is typically used in place of an abstract class when there is no default implementation to inherit.
true
100
Higher the level of abstraction, higher are the details.
False
101
Is one without a body that is declared with the reserved word abstract.
abstract method
102
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"); } }
All classes compile
103
Encapsulation and abstraction differ as ____________
Binding and Hiding respectively
104
MethodX might encounter an IOException or an AWTException, but handles neither. How should the header for methodX be written?
... methodX(...) throws IOException, AWTException
105
Which are the two blocks that are used to check error and handle the error?
Try and catch
106
What method of an Exception object returns a message string?
getMessage()
107
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.
2,3,5
108
What handles interface handle sequences?
List
109
What package contain all the collection classes?
java.util
110
What List class is synchronized?
Vector
111
You can't put null elements into Queues in the API?
true
112
Can we have a sorted and unordered set?
No
113
What type of collection does not extend the Collection interface?
Map
114
What is the difference between HashSet and TreeSet?
HashSet maintains no order while TreeSet maintains ascending order.
115
The erase() method of OutputStream Class flushes the current output stream.
false
116
This the standard output stream.
System.out
117
What is the difference between HashMap and Hashtable?
HashMap is not synchronized while the Hashtable is synchronized.
118
The standard error stream.
system.err
119
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();
i=System.in.read();
120
is the constructor of the FileReader class that creates a new file and get its file name in stringT
The FileReader (String file)
121
A method of the FileWriter class that flushes the data of FileWriter.
flush()
122
A constructor of the FileReader class that creates a new file and get its file name in string
FileReader (String file)
123
What class returns data in byte format like FileInputStream class?
Java FileReader
124
A method of the FileWriter class that is used to write the string into FileWriter.
write (String text)
125
A method of the FileReader class that is used to return a character in ASCII form. It returns -1 at the end of file.
read ()
126
the constructor of the FileReader class that creates a new file and get its file name in file objects.
FileReader (File file)
127
A method of the FileWriter class that is used to write char array into FileWriter.
write (char[] c)
128
a sequence of data.
Stream
129
It is the superclass of all classes representing an output stream of bytes. It accepts output bytes and sends them to some sink.
OutputStream
130
the standard input stream.
System.in
131
What is the design pattern followed by Iterator?
Iterator design pattern
132
What interface is not a part of Java's collection framework?
SortedList
133
What is the correct difference between ArrayList and LinkedList?
ArrayList uses a dynamic array whereas the LinkedList uses doubly linked list.
134
Which List would you use if wanted fast access and were doing lots of insertions and deletions?
LinkedList
135
What is the method to convert the array of strings into a list?
Arrays class asList() method
136
What is returned from both the compare() and compareTo() methods?
int
137
Which List would you use if wanted fast access and were doing lots of insertions and deletions?
LinkedList
138
What type of Queue is a PriorityQueue?
139
What do maps care about
Uniqueness
140
What is the difference between the Iterator and Enumeration?
Iterator can traverse legacy and non-legacy containers whereas the Enumeration can traverse only legacy containers.
141
What type of collection would we use if we wanted no duplicates?
Set
142
is used to process the input and produce the output.
Java I/O (Input and Output)
143
Automatically created streams are attached with the console.
True
144
is used to read data from a source; it may be a file, an array, peripheral device
InputStream
145
In using __________, unlike FileOutputStream class, you don't need to convert string into byte array because it provides method to write string directly.
FileWriter class
146
is used to read data from the file.
Java FileReader class
147
the constructor of the FileReader class that creates a new file and get its file name in string
ReaderFile (String file)
148
Java language is originally called ______
the 'Oak'
149
a general-purpose, concurrent, class-based, object- oriented language that is specifically designed to have as few implementation dependencies as possible.
Java
150
They are compiled into a format called bytecode (files with .class extension), which can be executed by a Java interpreter.
The Java source code files (files with .java extension)
151
It was intended for use in Sun’s project research to work on a programming software to control electronic devices.
Java
152
This defines a class, a template for an object of derived type HelloWorld
class HelloWorld
153
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
public
154
This is the state of the method, it is static because it must be called before the class that hosts the method is instantiated
static
155
It returns _______ This is because the Java interpreter does not expect to receive or process any output from the class.
void
156
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)
System.out.println( )
157
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.
Identifiers
158
three (3) types of Java Comments
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.