PRO192 - PRACTICE FE
Which of the following stream is/are used to handle primitive data types? Select one: a. DataInputStream b. All the above. c. BufferedOutputStream d. FileOutputStream e. FileInputStream
a. DataInputStream
A protected member can be accessed in, Select one: a. a non-subclass of the same package b. the same class c. a non-subclass of different package d. a subclass of the same package e. a subclass of different packag
a. a non-subclass of the same package
Suppose that the class Mystery is derived from the class Secret. The following statements are legal in Java. Secret secRef; Mystery mysRef = new Mystery(); secRef = mysRef; Select one: a. true b. false
a. true
What is the output of this program? class Test { public static void main(String[] args){ String str1 = "ABC"; String str2 = new String("ABC"); System.out.println(str1.equals(str2)); } } Select one: a. true b. false
a. true
Which of the following package is automatically imported to your program file? Select one: a. java.util b. java.lang c. java.net d. java.io e. java.math.
b. java.lang
The package provide some of the most useful Java classes that are frequently needed in all types of applications. Select one: a. java.awt b. java.util c. java.lang d. java.io
b. java.util
The java.util.Vector class provides storage for object references in the order of addition and automatically expands as needed. Which of the following classes is closest in function to the Vector class? Select one: a. java.util.LinkedList b. java.util.ArrayList c. java.util.Hashtable d. java.util.List
b. java.util.ArrayList
What is the output of this program? class test { public static void main(String[] args) throws Exception { String str ="Hello"; System.out.println(str.substring(3)); System.out.println(str.charAt(0)+""); } } Select one: a. Compile error b. loH c. lol d. Lo
b. loH
String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 + "equals" + s2 + "->" + s1.equals(s2)); What is the output of the following code? Select one: a. Hello equals Hello -> hello. b. Hello equals Hello -> false c. Hello equals Hello -> true d. Hello equals Hello -> 1 e. Hello equals Hello -> 0
c. Hello equals Hello -> true
Which class is the superclass of all the input stream class Select one: a. FileInputStream b. Stream c. InputStream d. Input
c. InputStream
_____ is a wrapper class for int data type Select one: a. Long b. Double c. Integer d. Byte
c. Integer
Which of the following statements about the reference super is true? Select one: a. It can only be used once in a program. b. It must be the last statement of the constructor. c. It must be the first statement of the constructor. d. It must be used every time a method from the superclass is called.
c. It must be the first statement of the constructor.
The ___________ method is used to replace a character in a StringBuffer, with another at a specified position. Select one: a. replace() b. setStringAt c. setCharAt d. replaceCharAt()
c. setCharAt
What is the output of the following code? class Shift { public static void main (string args[ ]) { int x=7; System.out.println("x>>>1=" +(x>>>1)); } } Select one: a. x>>>1=4 b. x>>>1=2. c. x>>>1=6 d. x>>>1=3 e. x>>>1=5
d. x>>>1=3
Which of the following exception is caused when a math error such as division by zero occurs? Select one: a. ArithmaticException b. ArrayIndex OutofBoundException. c. DivisionByZeroException d. NumberFormatException e. IOException
a. ArithmaticException
Collections Framework provides classes and interfaces for storing and manipulating groups of object in a standardized way Select one: a. TRUE b. FALSE
a. TRUE
MyList is a generic class that has a generic method add(), if we can write code as follows: MyList list = new MyList(); list.add(new Object()); Select one: a. TRUE b. FALSE
a. TRUE
The bounded wildcard "? extends T" means "any class that is T or extends from T" Select one: a. TRUE b. FALSE
a. TRUE
An abstract class can contain ____. Select one: a. abstract and non-abstract methods b. only non-abstract methods c. only abstract methods d. nothing
a. abstract and non-abstract methods
HashSet class guarantees the order of elements Select one: a. TRUE b. FALSE
b. FALSE
Redefining a method of a superclass is also known as overloading a method. Select one: a. True b. False
b. False
________ class reads bytes from a file Select one: a. FileOutputStream b. FileInputStream c. InputStream d. FileInput
b. FileInputStream
Is the following code legal? try { } finally { } Select one: a. NO b. YES
b. YES
The extends keyword creates a new Select one: a. Object. b. Superclass c. Subclass d. Instance e. Baseclass
c. Subclass
_____ is used to arrange the keys in a sorted order and store elements in a tree structure Select one: a. TreeSet b. TreeHashSet c. TreeMap d. HashMap
c. TreeMap
Consider the following class definitions. public class BClass { private int x; private double y; public void print() { } } public class DClass extends BClass { private int a; private int b; public void print() { } } Suppose that you have the following statement. DClass dObject = new DClass(); How many instance variables DObject has? Select one: a. 0 b. 4 c. None of these d. 2
d. 2
class Main { static int m; Main() { m ++; } public static void main(String [] args) { Main m1 = new Main(); Main m2 = new Main(); Main m3 = new Main(); System.out.println(m); } } } Select one: a. 2 b. Compile error c. 1 d. 3
d. 3
What is the output of this program? class Test { public int a = 0; public static void change(Test t) { t.a = 5; } public static void main(String[] args){ Test t = new Test(); t.a = 1; change(t); System.out.println(t.a); } } Select one: a. Compile error b. 1 c. 0 d. 5
d. 5
InputStream class is an ________ Select one: a. base class b. interface c. class d. abstract class
d. abstract class
Which classes allows duplication of elements. Select one or more: a. Vector b. SortedSet c. Set
a. Vector
If a class implements an interface, it must ____. Select one: a. override all variables from the interface b. provide definitions for each of the methods of the interface c. override all constants from the interface d. rename all the methods in the interface
b. provide definitions for each of the methods of the interface
What is the extension name of a Java source code file? Select one: a. .exe b. .class c. .javac. d. .java e. .obj
d. .java
A process that involves recognizing and focusing on the important characteristics of a situation or object is known as: Select one: a. Inheritance b. Encapsulation c. Object persistence. d. Polymorphism e. Abstraction
e. Abstraction
Among these expressions, which is(are) of type String? Select one: a. (I), (II) and (III) above. b. I. "0" c. III. '0' d. II. "ab" + "cd" e. Both (I) and (II) above
e. Both (I) and (II) above
Which of the following is not a valid String Constant? Select one: a. 'x' b. "X" c. "Hello" d. "Hello Guys". e. "2002"
a. 'x'
Which of the following are the wrapper classes? I. Random. II. Byte. III. Integer. IV. Short. V. Double. Select one: a. (II), (III), (IV) and (V) above b. (II), (III) and (IV) above c. All (I), (II), (III), (IV) and (V) above. d. (II), (III) and (V) above e. (III), (IV) and (V) above
a. (II), (III), (IV) and (V) above
What is the output of the following program: public class Main { static int i = 1; public static void main(String args[]) { System.out.print(i+" , "); m(i); System.out.print(i); } public static void m(int i) { i += 2; } } Select one: a. 1 , 1 b. 0 , 0 c. none of the above. d. 3 , 1 e. 1 , 3
a. 1 , 1
What is the output of the following Java code? int count = 1; int num = 25; while (count < 25) { num = num - 1; count++; } System.out.println(count + " " + num); Select one: a. 25 1 b. 24 0 c. 25 0 d. 24 1
a. 25 1
import java.util.*; class Array { public static void main(String args[]) { int array[] = new int [5]; for (int i = 5; i > 0; i--) array[5-i] = i; Arrays.fill(array, 1, 4, 8); for (int i = 0; i < 5 ; i++) System.out.print(array[i]); } } Select one: a. 58881 b. 12885 c. 54881 d. 12845
a. 58881
Which statement is not true in java language? Select one: a. A private member of a class cannot be accessed by the methods of the same class. b. A private member of a class cannot be accessed from its derived class. c. A public member of a class can be accessed in all the packages. d. None of the above. e. A protected member of a class can be accessed from its derived class.
a. A private member of a class cannot be accessed by the methods of the same class.
Which statement is not true in java language? Select one: a. A private member of a class cannot be accessed by the methods of the same class. b. A private member of a class cannot be accessed from its derived class. c. A public member of a class can be accessed in all the packages. d. A protected member of a class can be accessed from its derived class. e. None of the above.
a. A private member of a class cannot be accessed by the methods of the same class.
What is the output of this program? class Test { int a = 1; public Test(int a) { this.a = a; } public void print() { System.out.println(""+a); } public static void main(String[] args){ Test t1 = new Test(2); Test t2 = new Test(); t1.print(); t2.print(); } } Select one: a. Compile error b. 21 c. 22 d. 12
a. Compile error
A collection is a container that helps to group multiple elements of Object class into a single unit Select one: a. FALSE b. TRUE
a. FALSE
Is the following inteface valid? public interface TestInterface { void aMethod(int aValue) { System.out.println("Hi Mom"); } } Select one: a. FALSE b. TRUE
a. FALSE
An abstract class can only contain abstract methods. Select one: a. False b. True
a. False
The superclass inherits all its properties from the subclass. Select one: a. False b. True
a. False
The superclass inherits all its properties from the subclass. Select one: a. False b. True
a. False
Which of the following statements creates an input stream that can be used to read bytes from a file file.txt Select one: a. FileInputStream f1 = new FileInputStream("/file.txt"); b. DataInputStream f1 = new DataInputStream("//file.txt"); c. ByteArrayInputStream f1 = new ByteArrayInputStream("//file.txt"); d. InputStream f1 = new InputStream("\file.txt");
a. FileInputStream f1 = new FileInputStream("/file.txt");
Which of the following is a character stream? Select one: a. FileReader b. FileInputStream c. BufferedInputStream d. FileOutputStream. e. DataInputStream
a. FileReader
String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 + "equals" + s2 + "->" + s1.equals(s2)); What is the output of the following code? Select one: a. Hello equals Hello -> true b. Hello equals Hello -> 1 c. Hello equals Hello -> hello. d. Hello equals Hello -> false e. Hello equals Hello -> 0
a. Hello equals Hello -> true
All the methods of the _____ class are static Select one: a. Math b. System c. Runtime d. String
a. Math
Statement File f = new File() is used to create a new file? Select one: a. No b. Yes
a. No
The classes Reader and Writer are derived from the class ____. Select one: a. Object b. Inputs c. Outputs d. Streams
a. Object
Which of the following stream is used for Object Serialization? Select one: a. ObjectOutputStream b. ObjectReader. c. DataInputStream d. DataOutputStream e. ObjectWriter
a. ObjectOutputStream
Which of these interface must contain a unique element? Select one: a. Set b. List c. Collection d. Array
a. Set
_____ class doesn't permit duplication of elements Select one: a. Set b. Stack c. Vector d. Queue
a. Set
Which of these interface is not a part of Java's collection framework? Select one: a. SortedList b. SortedMap c. List d. Set
a. SortedList
A collection is a container that helps to group multiple elements of Object class into a single unit Select one: a. TRUE b. FALSE
a. TRUE
A stream produces and consumes information Select one: a. TRUE b. FALSE
a. TRUE
The constructor FileOutputStream(String filename, boolean flag) creates an OutputStream that can be used to write bytes to a file Select one: a. TRUE b. FALSE
a. TRUE
Which of the following statements is NOT true about creating your own exceptions? Select one: a. The exception class that you define extends either the class Throwable or one of its subclasses. b. Typically, constructors are the only methods that you include when you define your own exception class. c. d. You must throw your own exceptions using the throw statement. d. If you have created an exception class, you can define other exception classes extending the definition of the exception class you create
a. The exception class that you define extends either the class Throwable or one of its subclasses.
An overloaded method consists of (select 2), Select one or more: a. The same method name with different types of parameters b. The same method name with different number of parameters c. The same method name and same number and type of parameters with different return type d. Other answers e. There is no concept of overloaded method
a. The same method name with different types of parameters b. The same method name with different number of parameters
How many finally blocks can there be in a try/catch structure? Select one: a. There can be 0 or 1 following the last catch block. b. There is no limit to the number of finally blocks following the last catch block. c. There can be 1 following each catch block. d. There must be 1.
a. There can be 0 or 1 following the last catch block.
Which of the following is NOT a typical action of the catch block? Select one: a. Throwing the exception b. Completely handling the exception c. Rethrowing the same exception for the calling environment d. Partially processing of the exception
a. Throwing the exception
Is the following interface valid? public interface NewInterface { } Select one: a. YES b. NO
a. YES
InputStream class is an ________ Select one: a. abstract class b. interface c. class d. base class
a. abstract class
An abstract class ____. Select one: a. cannot be instantiated b. is the base class of all other classes c. does not have any subclasses d. is a superclass with many subclasses
a. cannot be instantiated
What is the correct syntax for defining a new class Parakeet based on the superclass Bird? Select one: a. class Parakeet extends Bird{ } b. class Parakeet isa Bird{ } c. class Bird defines Parakeet{ } d. class Bird hasa Parakeet{ }
a. class Parakeet extends Bird{ }
To declare a constant MAX_LENGTH as a member of the class, you write Select one: a. final static MAX_LENGTH = 99.98; b. final static float MAX_LENGTH = 99.98; c. static double MAX_LENGTH = 99.98; d. final static double MAX_LENGTH = 99.98;. e. final double MAX_LENGTH = 99.98;
a. final static MAX_LENGTH = 99.98;
Consider the following variable declarations: int i; float j; boolean k; Which of the following is correct initialization? Select one: a. i = 1; j = 1.0f; k = true; b. i = 1; j = 1.0; k = true; c. i = 1; j = 1.0; k = "true"; d. i = 1; j = 1.0f; k = "true"; e. i = 1; j = 1.0f; k = True;
a. i = 1; j = 1.0f; k = true;
File class is under package? Select one: a. java.io b. There is no such kind of class c. java.util d. java.lang
a. java.io
How the main method header is written in Java? Select one: a. public static void main(String[] args) b. public void main(String[] args). c. public static void Main(String[] args) d. public static main(String[] args) e. public static void main(string[] args)
a. public static void main(String[] args)
Which method of DataInput is used to read and return one byte Select one: a. readByte() b. readInt() c. readBytes() d. readOneByte()
a. readByte()
What type of inheritance does Java support? Select one: a. single inheritance b. multiple inheritance c. double inheritance d. Java does not support inheritance
a. single inheritance
Which of these combinations of switch expression types and case label value types are legal within a switch statement? Select one: a. switch expression of type int and case label value of type char b. switch expression of type float and case label value of type int c. switch expression of type char and case label value of type long d. switch expression of type boolean and case label value of type boolean. e. switch expression of type byte and case label value of type float
a. switch expression of type int and case label value of type char
What is the output of this program? class Test { public static void main(String[] args){ String str1 = "ABC"; String str2 = "ABC"; System.out.println(str1==str2); } } Select one: a. true b. false
a. true
Consider the following class definition: public class MyClass { private int value; public void setValue(int i){ /* code */ } // Other methods... } The method setValue assigns the value of i to the instance field value. What could you write for the implementation of setValue (select 2)? Select one or more: a. value = i; b. this.value = i; c. value == i; d. i = value e. i == value
a. value = i; b. this.value = i;
________ method adds a specified element to the begining of the vector Select one: a. vector.add() b. vector.insert() c. vector.insertElement() d. vector.addOneElement()
a. vector.add()
Among these expressions, which is(are) of type String (select 2)? a. '0' b. "0" c. "ab" + "cd" d. '\t' e. '\n'
b. "0" c. "ab" + "cd"
Which of the following contain error? I. int x[] = int[10];. II. int[] y = new int[5]; III. x = y = new int[10]; IV. int a[] = {1, 2}; int b[]; b = a; V. int i = new int(10); Select one: a. (I), (IV) and (V) above b. (I), (III) and (V) above c. (III), (IV) and (V) above d. All (I), (II), (III), (IV) and (V) above. e. (I), (III) and (IV) above
b. (I), (III) and (V) above
The default value of a static integer variable of a class in Java is, Select one: a. -1 b. 0 c. 1 d. null e. Garbage value
b. 0
Which of the following statements regarding the 'final' modifier are true? (Select 3) Select one or more: a. A method declared 'final' can be overridden in the subclass b. A variable defined as 'final' is a constant c. A class declared as being 'final' cannot be subclassed d. A method declared 'final' cannot be overridden in the subclass e. A class declared as being 'final' can be subclassed
b. A variable defined as 'final' is a constant c. A class declared as being 'final' cannot be subclassed d. A method declared 'final' cannot be overridden in the subclass
If class Dog has a subclass Retriever, which of the following is true? Select one: a. Because of single inheritance, Dog can have no other subclasses. b. Because of single inheritance, Retriever can extend no other class except Dog. c. The relationship between these classes implies that Retriever "has-a" Dog. d. The relationship between these classes implies that Dog "is-a" Retriever.
b. Because of single inheritance, Retriever can extend no other class except Dog.
Suppose that the class Mystery is derived from the class Secret. Consider the following statements: Secret mySecret = new Secret(); Secret secRef; Mystery myMystery = new Mystery(); Mystery mysRef; secRef = myMystery; Which of the following statements is legal in Java? (i) mysRef = (Mystery) mySecret; (ii) mysRef = (Mystery) secRef; Select one: a. Only (i) b. Both (i) and (ii) c. None of these d. Only (ii)
b. Both (i) and (ii)
Which of the following is not a valid statement? Select one: a. Class methods can access class variables and class methods directly b. Class methods can access instance variables or instance methods directly c. Instance methods can access class variables and class methods directly d. Instance methods can access instance variables and instance methods directly e. Class methods cannot use 'this' keyword as there is no instance for this to refer to.
b. Class methods can access instance variables or instance methods directly
What is the output of this program? class Test{ ArrayList list = new ArrayList<>(); public void add(T entity) { list.add(entity); System.out.println(entity.toString()); } public static void main(String[] args){ Test t = new Test<>(); t.add("abc"); t.add(123); } } Select one: a. abc b. Compile error c. 123 d. abc123
b. Compile error
Reader an Writer classes are abstract classes used for reading and writing character streams and object treams Select one: a. TRUE b. FALSE
b. FALSE
What will be printed as the output of the following program? public class testincr { public static void main(String args[]) { int i = 0; i = i++ + i; System.out.println("I = " +i); } } Select one: a. I = 2 b. I = 1 c. I = 0 d. Compile-time Error. e. I = 3
b. I = 1
In object-oriented programming, the process by which one object acquires the properties of another object is called Select one: a. Encapsulation b. Inheritance c. Overloading d. Polymorphism e. Overriding
b. Inheritance
Which of the following statements about the reference super is true? Select one: a. It must be used every time a method from the superclass is called. b. It must be the first statement of the constructor. c. It can only be used once in a program. d. It must be the last statement of the constructor.
b. It must be the first statement of the constructor.
What is the error in the following class definitions? abstract class xy { abstract sum (int x, int y) { } } Select one: a. No error. b. Method is not defined properly c. Class header is not defined properly. d. Constructor is not defined. e. Method is defined properly
b. Method is not defined properly
The _________ class is the top of the class hierarchy. Select one: a. Class b. Object c. Component d. System
b. Object
Which of the following stream is used for Object Serialization? Select one: a. ObjectWriter b. ObjectOutputStream c. DataInputStream d. DataOutputStream e. ObjectReader.
b. ObjectOutputStream
Consider the following statements: I. A class can be declared as both abstract and final. II. A class declared as final can be extended by defining a sub-class. III. Resolving calls to methods dynamically at run-time is called late binding. IV. The class Object defined by Java need not be a super class of all other classes. Identify the correct statement from the following: Select one: a. Both (I) and (II) above b. Only (III) above. c. Both (I) and (III) above d. Both (II) and (IV) above e. Both (III) and (IV) above
b. Only (III) above.
The process of writing objects to a byte stream called ___________ Select one: a. Abstraction b. Serialization c. IO handling d. Deserialization
b. Serialization
In a Vector, the size of the vector can be increased or decreased at runtime Select one: a. FALSE b. TRUE
b. TRUE
The constructor ArrayList() creates an empty array Select one: a. FALSE b. TRUE
b. TRUE
The constructor FileOutputStream(String filename, boolean flag) creates an OutputStream that can be used to write bytes to a file Select one: a. FALSE b. TRUE
b. TRUE
What will be the result of attempting to compile and run the following code? class MyClass { public static void main(String[] args) { boolean b = false; int i = 1; do { i++; b = !b; } while (b); System.out.println(i); } } Select one: a. The code will fail to compile, since the assignment b = !b is not allowed b. The code will compile without error and will print 3 when run. c. The code will fail to compile, since b is an invalid conditional expression in thedo-while statement d. The code will compile without error and will print 1 when run e. The code will compile without error and will print 2 when run
b. The code will compile without error and will print 3 when run.
Given Main class class Main { String value; public Main(String value) { this.value = value; } public static void main(String [] args) { Main m = new Main(); System.out.println(m.value); } } What is output of given code? Select one: a. There is nothing is printed b. The compiler will raise an error because there is no such constructor at the code Main m = new Main() c. null d. None of the others
b. The compiler will raise an error because there is no such constructor at the code Main m = new Main()
What would be the result of attempting to compile and run the following program? class MyClass { static MyClass ref; String[] arguments; public static void main(String[] args) { ref = new MyClass(); ref.func(args); } public void func(String[] args) { ref.arguments = args; } } Select one: a. The program will fail to compile, since the argument args passed to the static method main() cannot be passed on to the non-static method func() b. The program will compile and run successfully. c. The program will fail to compile, since the non-static method func() cannot access the static variable ref d. The program will compile, but will throw an exception when run e. The program will fail to compile, since the static method main() cannot have a call to the non-static method func()
b. The program will compile and run successfully.
is any wrong with following code? void test(int x) { switch (x) { case 1: case 2: case 0: default: case 4: } } Select one: a. Each case section must end with a break statement b. There is nothing wrong with the code. c. The variable x does not have the right type for a switch expression d. The case label 0 must precede case label 1 e. The default label must be the last label in the switch statement
b. There is nothing wrong with the code.
Will this following code compile? try { } catch (Exception e) { } catch (ArithmeticException a) { } Select one: a. This code will compile b. This code will not compile
b. This code will not compile
Which classes allows duplication of elements Select one: a. Set b. Vector c. SortedSet
b. Vector
________ allow access to lements based on their position, but not allow to search a specific element Select one: a. HashSet b. Vector c. LinkedHashSet d. TreeSet
b. Vector
What is the key difference between the java.util.Vector and java.util.ArrayList classes? Select one: a. There is no difference . b. Vector is heavily synchronized, while ArrayList is not. c. Vector requires less memory. d. ArrayList implements the Collection interface.
b. Vector is heavily synchronized, while ArrayList is not.
What is the output of this program? class Test { public static void main(String[] args){ String str1 = "ABC"); String str2 = new String("ABC"); System.out.println(str1==str2); } } Select one: a. true b. false
b. false
If a class implements an interface, it must ____. Select one: a. rename all the methods in the interface b. provide definitions for each of the methods of the interface c. override all constants from the interface d. override all variables from the interface
b. provide definitions for each of the methods of the interface
A method having _____ access specification can be viewed from any package or any class Select one: a. private b. public c. protected d. default e. package
b. public
How the main method header is written in Java? Select one: a. public static main(String[] args) b. public static void main(String[] args) c. public static void main(string[] args) d. public void main(String[] args). e. public static void Main(String[] args)
b. public static void main(String[] args)
Analyze the following code: public class Test { public static void main(String[] args) { String s = new String("Welcome to Java"); Object o = s; String d = (String)o; } } Select one: a. s, o, and d reference the same String object b. s,o,and d doesnot reference the same String object. c. When casting o to s in String d = (String)o, the contents of o is changed d. When assigning s to o in Object o = s, a new object is created e. When casting o to s in String d = (String)o, a new object is created
b. s,o,and d doesnot reference the same String object.
Object oriented inheritance models the Select one: a. "contains" of relationship. b. inheritance does not describe any kind of relationship between classes c. "is a kind of" relationship d. "want to be" relationship e. "has a" relationship
c. "is a kind of" relationship
Which of the following classes are available in the java.lang package? I. Stack. II. Object. III. Math. IV. String. V. StringBuffer. Choose the correct option from the following: Select one: a. (II), (III) and (IV) above b. All (I), (II), (III), (IV) and (V) above. c. (II), (III), (IV) and (V) above d. (II), (IV) and (V) above e. (III), (IV) and (V) above
c. (II), (III), (IV) and (V) above
Consider the following Java program : public class Compute { public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x <= 10) { if (x%2 == 0) result += x ; ++ x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? Select one: a. 35 b. 25 c. 30 d. 55 e. 45
c. 30
How many characters be represented in Unicode? Select one: a. 256 b. None of the others c. 65536 d. 65537 e. 65535
c. 65536
What is the output of this program? class Test { public static void main(String[] args){ HashSet set = new HashSet(); set.add("ABC"); set.add("ABC"); set.add("CDF"); Iterator iterator = set.iterator(); while(iterator.hasNext()) { System.out.println(iterator.next().toString()); break; } } } Select one: a. ABCABCCDF b. Compile error c. ABC d. ABCCDF
c. ABC
A process that involves recognizing and focusing on the important characteristics of a situation or object is known as: Select one: a. Inheritance b. Object persistence. c. Abstraction d. Encapsulation e. Polymorphism
c. Abstraction
Which of these are legal identifiers. Select one: a. number_1 b. number_a c. All of the above. d. $1234
c. All of the above.
When is a finally{} block executed? Select one: a. Only when an exception is thrown by a try block b. At the end of a program c. Always after the execution of a try block, regardless of whether or not an exception is thrown d. Only when there are no exceptions thrown
c. Always after the execution of a try block, regardless of whether or not an exception is thrown
Which of the following is not true? Select one: a. A class which is implementing an interface must implement all the methods of the interface. b. An interface is a solution for multiple inheritance in java. c. An interface can implement another interface. d. None of the above. e. An interface can extend another interface.
c. An interface can implement another interface.
Which statement is true regarding an object? Select one: a. An object is not an instance of a class. b. An object is a variable c. An object is an instance of a class d. An object is what classes instantiated are from e. An object is a reference to an attribute
c. An object is an instance of a class
In which stream, a data unit is a physical byte. Select one: a. Character stream b. Object stream c. Binary low-level stream d. Binary high-level stream
c. Binary low-level stream
An overloaded method consists of, Select one: a. III. The same method name and same number and type of parameters with different return type b. I. The same method name with different types of parameters c. Both (I) and (II) above d. (I), (II) and (III) above. e. II. The same method name with different number of parameters
c. Both (I) and (II) above
What is the output of this program? class A { public void print() { System.out.println("A"); } } class B extends A { public void print() { super.print(); System.out.println("B"); } } class C extends B { public void print() { System.out.println("C"); } } class Test { public static void main(String[] args) throws Exception { A a = new C(); a.print(); } } Select one: a. ABC b. A c. C d. Compile error
c. C
What is the output of this program? class test { String str ="Hello"; public static void main(String[] args) throws Exception { System.out.println(str.substring(3)); System.out.println(str.charAt(0)+""); } } Select one: a. lol b. loH c. Compile error d. lo
c. Compile error
Given the following member declarations, which statement is true? int a; //(1) static int a; //(2) int f() { return a; } //(3) static int f() { return a; } //(4) Select one: a. Declarations (1) and (3) cannot occur in the same class definition b. None of the above. c. Declarations (1) and (4) cannot occur in the same class definition d. Declarations (2) and (3) cannot occur in the same class definition e. Declarations (2) and (4) cannot occur in the same class definition
c. Declarations (1) and (4) cannot occur in the same class definition
________ is the process of storing objects into a datasource and serialization is the process of retrieve objects from a datasource Select one: a. Abstraction b. IO handling c. Deserialization d. Serialization
c. Deserialization
Which of the following statements is true? Select one: a. Inheritance defines a has-a relationship between a superclass and its subclasses b. A class can extend any number of other classes c. Every java object has a public method named equals d. All of the above. e. Every java object has a public method named length
c. Every java object has a public method named equals
________ class reads bytes from a file Select one: a. FileInput b. FileOutputStream c. FileInputStream d. InputStream
c. FileInputStream
Consider, public class MyClass { public MyClass(){/*code*/} // more code... } To instantiate MyClass, you would write? Select one: a. MyClass mc = new MyClass; b. MyClass mc = MyClass(); c. MyClass mc = new MyClass(); d. MyClass mc = MyClass; e. The constructor of MyClass should be defined as, public void MyClass(){/*code*/}.
c. MyClass mc = new MyClass();
Consider the following statements about Java packages: I. Packages don't provide a mechanism to partition all class names into more manageable chunks. II. Packages provide a visibility control mechanism. III. One of the important properties of a package is that all classes defined inside a package is accessible by code outside that package. IV. The .class files for classes declared to be part of a package can be stored in multiple directories. Which of them is correct? Select one: a. All (I), (II), (III) and (IV) above are wrong. b. Only (III) above c. Only (II) above d. Only (IV) above e. Only (I) above
c. Only (II) above
The process of reading and writing objects to a byte stream called ___________ Select one: a. Deserialization b. Abstraction c. Serialization d. IO handling
c. Serialization
Which operator is used to determine if an object is of a particular class type? Select one: a. The dot (.) operator b. The operator new c. The instanceof operator d. The + operator
c. The instanceof operator
What happens in a method if there is an exception thrown in a try block but there is no catch block following the try block? Select one: a. The program ignores the exception. b. The program will not compile without a complete try/catch structure. c. The program throws an exception and proceeds to execute the finally block. d. The program terminates immediately.
c. The program throws an exception and proceeds to execute the finally block.
What is byte code in the context of Java? Select one: a. It is another name for a Java source file. b. The type of code generated by a Java Virtual Machine. c. The type of code generated by a Java compiler. d. It is another name for comments written within a program. e. It is the code written within the instance methods of a class.
c. The type of code generated by a Java compiler.
How many interfaces can a class implement? Select one: a. 1 b. 2 c. There is no limit to the number of interfaces that can be implemented by a single class. d. 0
c. There is no limit to the number of interfaces that can be implemented by a single class.
The output of this line: System.out.println("I loveV".substring(2+"love".length(),1)); Select one: a. An empty space b. Compile error c. Throw an exception d. None of the others
c. Throw an exception
What is the correct syntax for defining a new class Parakeet based on the superclass Bird? Select one: a. class Bird hasa Parakeet{ } b. class Parakeet isa Bird{ } c. class Parakeet extends Bird{ } d. class Bird defines Parakeet{ }
c. class Parakeet extends Bird{ }
To prevent any method from overriding, we declare the method as, Select one: a. static b. const c. final d. none of the above. e. abstract
c. final
An ____________ declaration contains signatures, but no implementations, for a set of methods, and might also contain constant definitions. Select one: a. data type b. abstract class c. interface d. object e. class
c. interface
Given Main class class Main { String value; public static void main(String [] args) { Main m = new Main(); System.out.println(m.value); } } What is output of given code? Select one: a. None of the others b. The compiler will raise an error because there is no constructor inside Main class c. null d. There is nothing is printed
c. null
class Point { int x,y; Point (int x, int y) { this.x = x; this.y = y; } public String toString() { return "Point[" +x+ "," +y+ "]"; } } public class Main{ public static void main (String args[]) { Point p = new Point (10,20); System.out.println("p=" +p);} } What is the output of the following code? Select one: a. p = Point[10,21]. b. p = Point[20,20] c. p = Point[10,20] d. p = Point[20,10] e. p = Point[11,20]
c. p = Point[10,20]
Which of these field declarations are legal within the body of an interface? Select one: a. final static answer =42 b. No error. c. public static int answer=42 d. int answer e. Private final static int answer = 42
c. public static int answer=42
class Main { static int m; static { m ++; } public static void main(String [] args) { System.out.println(Main.m); } } Select one: a. None of others b. The call "m++" is invalid because m is not yet initialized value c. 0 d. 1
d. 1
Which of the following is not true? Select one: a. An interface can extend another interface. b. None of the above. c. A class which is implementing an interface must implement all the methods of the interface. d. An interface can implement another interface. e. An interface is a solution for multiple inheritance in java.
d. An interface can implement another interface.
Consider the following class definition: public class MyClass { private int value; public void setValue(int i){ /* code */ } // Other methods... } The method setValue assigns the value of i to the instance field value. What could you write for the implementation of setValue? Select one: a. II. this.value = i; b. (I), (II) and (III) above. c. III. value == i; d. Both (I) and (II) and above e. I. value = i;
d. Both (I) and (II) and above
When creating your own class, and you want to make it directly support sorting, which interface must it implement? Select one: a. Sortator b. Comparator c. Sortable d. Comparable
d. Comparable
Which class is the superclass of all the input stream class Select one: a. FileInputStream b. Input c. Stream d. InputStream
d. InputStream
Consider the following program written in Java. class Selection{ public static void main(String args[]){ int x=7; if(x==2); //? Note the semicolon System.out.println("Number seven"); System.out.println("Not seven"); } } What would the output of the program be? Select one: a. Error b. Number seven c. Not seven d. Number seven Not seven e. 7
d. Number seven Not seven
Consider the following class definitions. public class BClass { private int x; public void set(int a) { x = a; } public void print(){ } } public class DClass extends BClass { private int y; public void set(int a, int b) { //Postcondition: x = a; y = b; } public void print(){ } } Which of the following is the correct definition of the method set of the class Dclass? (i) public void set(int a, int b) { super.set(a); y = b; } (ii) public void set(int a, int b) { x = a; y = b; } Select one: a. None of these b. Both (i) and (ii) c. Only (ii) d. Only (i)
d. Only (i)
Statement 1: A protected member of a class can be accessed from any class in the same package and from a subclass that is outside the package. Statement 2: A member of a class that is declared private can not be accessed only within the class but nowhere outside the class. Choose the correct answer? Select one: a. Both Statement 1 and Statement 2 are FALSE b. Both Statement 1 and Statement 2 are TRUE c. Statement 1 is FALSE, Statement 2 is TRUE d. Statement 1 is TRUE, Statement 2 is FALSE
d. Statement 1 is TRUE, Statement 2 is FALSE
Analyze the following code: public class Test { public static void main(String[] args) { int[] x = new int[5]; int i; for (i = 0; i < x.length; i++) x[i] = i; System.out.println(x[i]); } } Select one: a. The program has syntax error because i is not defined in the last statement in the main method b. The program displays 1 2 3 4 5. c. The program displays 0 1 2 3 4 d. The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException e. The program displays 4
d. The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException
What will be the result of attempting to compile and run the following program? public class Polymorphism { public static void main(String[] args) { A ref1 = new C(); B ref2 = (B) ref1; System.out.println(ref2.f()); } } class A { int f() { return 0; } } class B extends A { int f() { return 1; } } class C extends B { int f() { return 2; } } Select one: a. The program will compile without error and print 1 when run b. The program will fail to compile c. The program will compile without error and print 0 when run d. The program will compile without error and print 2 when run. e. The program will compile without error, but will throw a ClassCastException when run
d. The program will compile without error and print 2 when run
Given the following code, which statement is true? class MyClass { public static void main(String[] args) { int k = 0; int l = 0; for (int i=0;i<=3;i++) { k++; if (i==2) break; l++; } System.out.println(k+", "+l); } } Select one: a. The program will fail to compile if break is replaced by return b. The program will fail to compile if break is simply removed. c. The program will fail to compile d. The program will print 4, 3 when run if break is replaced by continue e. The program will print 3, 3 when run
d. The program will print 4, 3 when run if break is replaced by continue
What is the result of the expression 75.22 + "5.2"? Select one: a. The string in "80.42". b. The double value in 80.42 c. The string is "75.222.5" d. The string is "75.225.2" e. The long value is 80.
d. The string is "75.225.2"
How many interfaces can a class implement? Select one: a. 2 b. 1 c. 0 d. There is no limit to the number of interfaces that can be implemented by a single class.
d. There is no limit to the number of interfaces that can be implemented by a single class.
Consider the two methods (within the same class) public static int foo(int a, String s) { s = "Yellow"; a=a+2; return a; } public static void bar() { int a=3; String s = "Blue"; a = foo(a,s); System.out.println("a="+a+" s="+s); } public static void main(String args[]) { bar(); } What is printed on execution of these methods? Select one: a. a = 3 s = Yellow b. a = 3 s = Blue c. a = 5 s = Yellow d. a = 5 s = Blue e. none of the above.
d. a = 5 s = Blue
An abstract class ____. Select one: a. is the base class of all other classes b. is a superclass with many subclasses c. does not have any subclasses d. cannot be instantiated
d. cannot be instantiated
char chars[] = { 'a', 'b', 'c', 'd', 'e', 'f'}; String s = new String(chars, 2, 3); System.out.println (s); What is the output of the above code? Select one: a. acd. b. bcd c. abc d. cde e. deb
d. cde
Consider the following code: interface A { int a=5; int b=10;} Which of the following is possible for the above? Select one: a. class A implements B{int x;void add(){ x=a+b;}. b. class B implements A { int x;void add(){ a=20; b=10; x= a+b; }} c. class B extends A{ int x;void add(){ a=20; b=10; x= a+b; }} d. class B implements A{int x;void add(){ x= a+b; }} e. class B extends A { int x;void add(){ x= a+b; }}
d. class B implements A{int x;void add(){ x= a+b; }}
Given Main class class Main { static String value; public static void main(String [] args) { System.out.println(Main.value); } } What is output of given code? Select one: a. There is nothing is printed b. None of the others c. The call "Main.value" is invalid d. null
d. null
Consider the following program written in Java to answer this Question: 01.class StringEx{ 02.public static void main(String args[]) { 03.String s1="University of ICFAI"; 04.String s2="hello"; 05.String s3="HELLO"; 06.System.out.println(s1.substring(10,13)); 07.System.out.println(s2.equalsIgnoreCase(s3)); 08.} 09.} What would be the output of the statement indicated in line number 07 when the program is executed? Select one: a. of b. HELLO c. error d. true. e. false
d. true.
Which one of the following is not true? Select one: a. A class must be qualified as 'abstract' class, if it contains one abstract method. b. A class containing abstract methods is called an abstract class. c. Abstract methods should be implemented in the derived class. d. None of the above. e. An abstract class cannot have non-abstract methods.
e. An abstract class cannot have non-abstract methods.
Which of the following will produce an error? I. byte a1 = 2, a2 = 4, a3; II. short s = 16; III. a2 = s; IV. a3 = a1 * a2; Select one: a. Only (II) above b. Only (IV) above c. Only (III) above d. Both (I) and (IV) above. e. Both (III) and (IV) above
e. Both (III) and (IV) above
A method within a class is only accessible by classes that are defined within the same package as the class of the method.Given Main class class Main { static String value; public static void main(String [] args) { System.out.println(Main.value); } } What is output of given code? Select one: a. There is nothing is printed b. None of the others c. The call "Main.value" is invalid Incorrect d. null such restriction? Select one: a. Declare the method with the keyword private b. Declare the method with the keyword protected c. Declare the method with the keyword public and private. d. Declare the method with the keyword public e. Do not declare the method with any accessibility modifiers
e. Do not declare the method with any accessibility modifiers
Having a subclass offer a specialization for the method of a superclass is Select one: a. Polymorphism b. Overloading c. Inheritance d. Abstraction e. Overriding f. Encapsulation
e. Overriding
Given the code below: class A { public void print() { System.out.println("hi"); } } class B extends A { public void print() { System.out.println("bye"); } } What does each of the following code samples do: A a = new B(); a.print(); Select one: a. Prints "hi" b. Prints nothing c. The code throws a runtime exception. d. The code does not compile, the compiler returns a type error e. Prints "bye"
e. Prints "bye"
Analyze the following code and choose the correct answer: public class Foo { private int x; public static void main(String[] args) { Foo foo = new Foo(); System.out.println(foo.x); } } Select one: a. Since x is public it cannot be accessed from an object foo. b. You cannot create a self-referenced object; that is, foo is created inside the class Foo c. Since x is defined in the class Foo, it can be accessed by any method inside the class without using an object. You can write the code to access x without creating an object such as foo in this code d. Since x is private, it cannot be accessed from an object foo e. Since x is an instance variable, it cannot be directly used inside a main method. However, it can be accessed through an object such as foo in this code
e. Since x is an instance variable, it cannot be directly used inside a main method. However, it can be accessed through an object such as foo in this code
Given a class named Student, which of the following is a valid constructor declaration for the class? Select one: a. static Void Student { } b. Student Student { } c. private final Student { } d. Void Student { } e. Student (Student s) { }
e. Student (Student s) { }
When an overridden method is called from within a subclass, it will always refer to the version of that method defined by the Select one: a. Interpreter will choose randomly b. Compiler will choose randomly c. Super class d. None of the abvove. e. Subclass
e. Subclass
Which of the following statements is true? Select one: a. None of the above. b. The keyword implements is used to specify that a class inherits from another class c. The keyword implements is used to specify that an interface inherits from another interface d. The keyword extends is used to specify that a class inherits from an interface e. The keyword extends is used to specify that an interface inherits from another interface
e. The keyword extends is used to specify that an interface inherits from another interface
Analyze the following code. public class Test { public static void main(String[] args) { System.out.println(max(1, 2)); } public static double max(int num1, double num2) { System.out.println("max(int, double) is invoked"); if (num1 > num2) return num1; else return num2; } public static double max(double num1, int num2) { System.out.println("max(double, int) is invoked"); if (num1 > num2) return num1; else return num2; } } Select one: a. The program runs and prints 2 followed by "max(double, int)" is invoked b. The program cannot compile because you cannot have the print statement in a non-void method c. The program runs and prints 2 followed by "max(int, double)" is invoked d. The program runs and prints "max(int, double) is invoked" followed by 2. e. The program cannot compile because the compiler cannot determine which max method should be invoked
e. The program cannot compile because the compiler cannot determine which max method should be invoked
What is wrong in the following code? class TempClass { int i; public void TempClass(int j) { int i = j; } } public class C { public static void main(String[] args) { TempClass temp = new TempClass(2); } } Select one: a. The program compiles and runs fine b. All of the above. c. The program has a compilation error because TempClass does not have a default constructor d. The program compiles fine, but it does not run because class C is not public e. The program has a compilation error because TempClass does not have a constructor with an int argument
e. The program has a compilation error because TempClass does not have a constructor with an int argument
What modifier is to be used If you wish to declare that you want to no longer allow subclasses to override your variables or methods? Select one: a. abstract b. Finally c. synchronized d. volatile e. final
e. final
Suppose static void nPrint(String message, int n) { while (n > 0) { System.out.print(message); n--; } } What is the printout of the call Print('a', 4)? Select one: a. aaaaa b. aa c. aaaa d. aaa e. invalid call.
e. invalid call.
What is the output of the following code? class Bitwise { public static void main (string args[]) { int x=5, y=6; System.out.println("x&y=" +(x &y)); System.out.println("x|y=" +(x|y)); System.out.println("x^y=" +(x^y)); } } Select one: a. x&y=5x|y=7x^y=3 b. x&y=6x|y=7x^y=3 c. x&y=4x|y=8x^y=4. d. x&y=4x|y=8x^y=3 e. x&y=4x|y=7x^y=3
e. x&y=4x|y=7x^y=3