Podcast
Questions and Answers
Suppose the xMethod()
is invoked from a main method in a class as follows:
public static void main(String[] args) {
xMethod();
}
xMethod()
is ______ in the class.
Suppose the xMethod()
is invoked from a main method in a class as follows:
public static void main(String[] args) {
xMethod();
}
xMethod()
is ______ in the class.
If a variable is declared static
in a particular class, what does that mean?
If a variable is declared static
in a particular class, what does that mean?
Declare and construct an ArrayList
with an initial capacity of 20 references to Object
.
Declare and construct an ArrayList
with an initial capacity of 20 references to Object
.
Which of these cannot be declared static
?
Which of these cannot be declared static
?
Signup and view all the answers
Which of the following statements are true?
i. A subclass is a subset of a superclass.
ii. A subclass is usually extended to contain more functions and more detailed information than its superclass.
iii. "class A extends B
" means A is a subclass of B.
iv. "class A extends B
" means B is a subclass of A.
Which of the following statements are true?
i. A subclass is a subset of a superclass.
ii. A subclass is usually extended to contain more functions and more detailed information than its superclass.
iii. "class A extends B
" means A is a subclass of B.
iv. "class A extends B
" means B is a subclass of A.
Signup and view all the answers
Given a class named Student
, which of the following is a valid constructor declaration for the class?
Given a class named Student
, which of the following is a valid constructor declaration for the class?
Signup and view all the answers
Which option can we use in the try
block to stop the execution of the "finally" block?
try {
// option
} finally {
// code
}
Which option can we use in the try
block to stop the execution of the "finally" block?
try {
// option
} finally {
// code
}
Signup and view all the answers
Suppose the xMethod() is invoked from a main method in a class as follows:
public static void main(String[] args) { xMethod(); }
xMethod() is ____ in the class.
Suppose the xMethod() is invoked from a main method in a class as follows:
public static void main(String[] args) { xMethod(); }
xMethod() is ____ in the class.
Signup and view all the answers
Which option can we use in the try block to stop the execution of the "finally" block?
Which option can we use in the try block to stop the execution of the "finally" block?
Signup and view all the answers
What is printed as a result of executing the following code segment?
ArrayList p = new ArrayList(); p.add(7); p.add(2); p.add(2); p.remove(2); p.add(1); p.add(2); System.out.println(p);
What is printed as a result of executing the following code segment?
ArrayList p = new ArrayList(); p.add(7); p.add(2); p.add(2); p.remove(2); p.add(1); p.add(2); System.out.println(p);
Signup and view all the answers
What is printed as a result of executing the following code segment?
ArrayList aList = new ArrayList<Integer>(); alist.add(1); alist.add(2); alist.remove(1); alist.add(1, 3); alist.set(1, 4); alist.add(5); System.out.println(aList);
What is printed as a result of executing the following code segment?
ArrayList aList = new ArrayList<Integer>(); alist.add(1); alist.add(2); alist.remove(1); alist.add(1, 3); alist.set(1, 4); alist.add(5); System.out.println(aList);
Signup and view all the answers
Examine the following code:
ArrayList<String> list = new ArrayList<String>(); list.add("Andy" ); list.add("Bart" ); list.add("Carl" ); list.add("Doug"); list.add("Elmo" );
Which of the following will change the list so that it looks like:
Andy Bart Carl Doug
Examine the following code:
ArrayList<String> list = new ArrayList<String>(); list.add("Andy" ); list.add("Bart" ); list.add("Carl" ); list.add("Doug"); list.add("Elmo" );
Which of the following will change the list so that it looks like:
Andy Bart Carl Doug
Signup and view all the answers
What is the output of the following java code?
import java.util.ArrayList; class TestList { public static void main(String[] args) { ArrayList<String> al = new ArrayList<String>(); al.add("A"); al.add("B"); al.add("A"); al.add(null); System.out.println(al); } }
What is the output of the following java code?
import java.util.ArrayList; class TestList { public static void main(String[] args) { ArrayList<String> al = new ArrayList<String>(); al.add("A"); al.add("B"); al.add("A"); al.add(null); System.out.println(al); } }
Signup and view all the answers
Examine the following code:
public class Main { public static void main(String[] args) { List<Integer> mylist = new ArrayList(); System.out.println(mylist.add(5)); } }
What is the output of this java code?
Examine the following code:
public class Main { public static void main(String[] args) { List<Integer> mylist = new ArrayList(); System.out.println(mylist.add(5)); } }
What is the output of this java code?
Signup and view all the answers
Analyze the following code.
public class Test { public static void main(String args[]) { NClass nc = new NClass(); nc.t = nc.t++; } } class NClass{ int t; private NClass() { } }
Analyze the following code.
public class Test { public static void main(String args[]) { NClass nc = new NClass(); nc.t = nc.t++; } } class NClass{ int t; private NClass() { } }
Signup and view all the answers
Analyze the following code.
double[] array = {1, 2, 3}; ArrayList<Double> list = new ArrayList<>(Arrays.asList(array)); System.out.println(list);
Analyze the following code.
double[] array = {1, 2, 3}; ArrayList<Double> list = new ArrayList<>(Arrays.asList(array)); System.out.println(list);
Signup and view all the answers
Analyze the following code.
public class Test { public static void main(String[] args) { B b = new B(); b.m(5); System.out.println("i is " + b.i); } } class A { int i; public void m(int i) { this.i = i; } } class B extends A { public void m(String s) { } }
Analyze the following code.
public class Test { public static void main(String[] args) { B b = new B(); b.m(5); System.out.println("i is " + b.i); } } class A { int i; public void m(int i) { this.i = i; } } class B extends A { public void m(String s) { } }
Signup and view all the answers
Every JavaFX main class _____.
Every JavaFX main class _____.
Signup and view all the answers
Which of the following statements is true?
Which of the following statements is true?
Signup and view all the answers
To place a node in the left of a BorderPane p, use _____.
To place a node in the left of a BorderPane p, use _____.
Signup and view all the answers
Which of the following methods is NOT defined in the Animation class?
Which of the following methods is NOT defined in the Animation class?
Signup and view all the answers
To remove a node from the pane, use _____.
To remove a node from the pane, use _____.
Signup and view all the answers
Which of the following statements is correct to create a DataOutputStream to write to a file named out.dat?
Which of the following statements is correct to create a DataOutputStream to write to a file named out.dat?
Signup and view all the answers
After the following program is finished, how many bytes are written to the file t.dat?
import java.io.*; public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream(new FileOutputStream("t.dat")); output.writeShort(1234); output.writeShort(5678); output.close(); } }
After the following program is finished, how many bytes are written to the file t.dat?
import java.io.*; public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream(new FileOutputStream("t.dat")); output.writeShort(1234); output.writeShort(5678); output.close(); } }
Signup and view all the answers
Interfaces can be instantiated.
Interfaces can be instantiated.
Signup and view all the answers
The modifiers public and static can be written in either order “public static” or “static public”.
The modifiers public and static can be written in either order “public static” or “static public”.
Signup and view all the answers
Abstraction is supported by method overriding in java.
Abstraction is supported by method overriding in java.
Signup and view all the answers
You can override a static method defined in a superclass.
You can override a static method defined in a superclass.
Signup and view all the answers
You can write a constructor for an abstract class.
You can write a constructor for an abstract class.
Signup and view all the answers
If AbsClass is an abstract class, the expression x instanceof AbsClass is always false.
If AbsClass is an abstract class, the expression x instanceof AbsClass is always false.
Signup and view all the answers
Classes, methods, and instance variables can all be declared final.
Classes, methods, and instance variables can all be declared final.
Signup and view all the answers
What does the instanceof
operator evaluate to, if the left-hand-side object is a child of the right-hand-side class or is the same type as the class provided?
What does the instanceof
operator evaluate to, if the left-hand-side object is a child of the right-hand-side class or is the same type as the class provided?
Signup and view all the answers
Does the instanceof
operator work with interfaces?
Does the instanceof
operator work with interfaces?
Signup and view all the answers
What error does the program give if instanceof
operation is applied with a type that is always false?
What error does the program give if instanceof
operation is applied with a type that is always false?
Signup and view all the answers
A null reference is an instance of any class.
A null reference is an instance of any class.
Signup and view all the answers
What is the common use case of instanceof
operation?
What is the common use case of instanceof
operation?
Signup and view all the answers
How do you count the number of lines in a text file?
How do you count the number of lines in a text file?
Signup and view all the answers
How do you get the file name as user input?
How do you get the file name as user input?
Signup and view all the answers
Write a java method that takes an array of different elements' type and returns an array of only the ints from the array.
Write a java method that takes an array of different elements' type and returns an array of only the ints from the array.
Signup and view all the answers
Write a Java program that simulates a stock account with deposit and withdrawal operations. Use two threads: one for performing deposits and another for withdrawals. Ensure thread safety without using notify() or wait() methods.
Write a Java program that simulates a stock account with deposit and withdrawal operations. Use two threads: one for performing deposits and another for withdrawals. Ensure thread safety without using notify() or wait() methods.
Signup and view all the answers
Study Notes
Object Oriented Programming (SWE211)
- Course name: Object Oriented Programming (SWE211)
- Syllabus includes topics like A, Bus, 2A, B, C, 3A, B (likely course modules or assignments)
- Final revision material is included.
MCQ Questions and Answers (Various Topics)
-
Question 1 (Page 3):
xMethod()
invoked from amain
method is either static or an instance method. The correct answer is "c. a static method or an instance method". - Question 2 (Page 4): A static variable in a class has only one copy shared among all instances. The correct answer is "a) There is only one copy of it that all instances of the class can access or share".
-
Question 3 (Page 4): To declare an ArrayList with an initial capacity of 20, use
ArrayList<Object> list = new ArrayList<Object>(20);
. The correct answer is "a". - Question 4 (Page 5): Objects, variables, and constants can be static. Methods cannot be declared static. The correct answer is "a".
- Question 5 (Page 5): A subclass is an extension of a superclass, often with more functions and detail, and can be expressed as "class A extends B". If class A extends B, A is the subclass and B is the superclass. The correct answer for the second MCQ is "i, ii, and iii only"
-
Question 6 (Page 6): A valid constructor for a class named 'Student' is
Student(){}
(or possibly other forms). The correct answer is "d" - Question 7 (Page 7): Output question related to ArrayList operations and manipulation
-
Question 8 (Page 7): Output question related to ArrayList operations, including
add
,remove
,add(index, element)
, andset
. - Question 9 (Page 8): Given ArrayList code and output (page 8), the answer will depend on the operations called on the 'list'
-
Question 10 (Page 8): Given ArrayList code snippet (page 8), answer the question based on ArrayList operations (
clear
,remove
, etc.) -
Question 11 (Page 9): Output of a Java code snippet related to a
List
object. Determine what is printed. The correct answer is "a". -
Question 12 (Page 9): Output of a Java code snippet related to a
List
object that usesArrayList
. Determine what is printed. - Question 13 (Page 10): Analysis of a Java code snippet (page 10); the code has a compile-time error (because the access modifier to the constructor in the NClass class is private)
- Question 14 (Page 11): Java code analysis has a compile-time error as the original array is not an array of Objects. Correct answer is "A".
- Question 15 (Page 12): Analysis of Java method overriding. The correct answer is "b".
- Question 16 (Page 13): JavaFX main class overrides, implementation, or none. The correct answer is "b".
- Question 17 (Page 13): Statement about placement of Node, Pane, Scene, or Control objects in JavaFX.
- Question 18 (Page 14): Methods that are NOT defined in the Animation class
- Question 19 (Page 14): Methods used to remove node from a JavaFX Pane.
- Question 20 (Page 15): JavaFX program output
- Question 21 (Page 16): Correct statement to create a DataOutputStream for 'out.dat'.
- Question 22 (Page 17): Number of bytes written to a file named t.dat'.
- Question 23 (Page 18): True or False Questions related to interfaces, modifiers, abstractions, method overriding, constructors, instanceof, classes, methods,instance variables, abstraction, and more.
- Question 24 (Page 19): instanceof operator output
- Question 25 (Page 20): instanceof operator output
- Question 26 (Page 21): Analysis of Java instanceof statement. Output:Compile time error.
- Question 27 (Page 22): instanceof null reference behavior
- Question 28 (Page 23): instanceof statement output
- Question 29 (Page 24): instanceof behavior with different types.
- Question 30 (Page 25): Program to count lines in a text file
- Question 31 (Page 26): Program to count words in a text file
- Question 32 (Page 27): Program to count words by user-provided file input
- Question 33 (Page 28): Java method to extract integers from an array
- Question 34 (Page 29): Checking if a character in an array is a digit, whitespace, or letter
- Question 35 (Page 30): General terms for user events, event handlers, and adding ActionListeners
- Question 36 (Page 31): Creating a HashMap with iterator.
- Question 37 (Page 32): Accessing the reference to the current thread
- Question 38 (Page 33): Creating and running multiple threads, checking if threads run
- Question 39 (Page 34): Creating threads, checking if threads are run, waiting for the threads to finish
- Question 40 (Pages 35-38): Multithreaded program to simulate stock account operations
Additional Topics (General)
- Thread safety techniques
- File input/output concepts
- DataOutputStream, FileOutputStream
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz covers multiple choice questions related to the Object Oriented Programming (SWE211) course syllabus, including key concepts like static methods, variables, and ArrayLists. It's designed for final revision, helping students solidify their understanding of critical topics before exams.