0% found this document useful (0 votes)
6 views23 pages

Simulare Java Foundation v4

Uploaded by

stefan.tanasoff
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views23 pages

Simulare Java Foundation v4

Uploaded by

stefan.tanasoff
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Simulare Examen - Java Foundations

1) Which of the following are features of Java? (Choose 2)


a) robust
b) single threaded
c) multiplatform
d) dependency injection
2) Which of the following are features of Java?(Choose 1)
a) Interpreted
b) dynamic
c) complicated
d) architecture based
3) What should we understand from the slogan “Write Once and Run Anywhere”? (Choose 1)
a) Once you finished writing a program you can start running anywhere on the globe
b) Is a restriction to write a portion of code only one time in the app
c) Once compiled, the code will run on any JRE
d) You can use the app with any device the has the specific platform it was written on (eg: write on Windows, you
can use only with windows)
4) Which of the following are concepts of OOP(Object Oriented Programming)? (Choose 3)
a) Polymorphism
b) Encapsulation
c) Multithread
d) Portable
e) Inheritance
5) Which of the following keywords are specific for encapsulation? (Choose 2)
a) static
b) final
c) public
d) private
e) extends
6) Which of the following keywords are specific for inheritance? (Choose 1)
Page 1 of 23
a) static
b) final
c) public
d) extends
7) An abstraction denotes the essential properties and behaviours of an object that differentiate from others. (Choose 1)
a) True
b) False
8) What is true about Java Development Kit (JDK)? (Choose 2)
a) The JDK is a software package that contains a variety of tools and utilities that make it possible to develop,
package, monitor and deploy applications that build for any standard Java platform
b) It includes the compiler (javac) and the JRE(Java Runtime Environment)
c) Contains a variety of projects and tutorials to help beginners to develop apps
d) It only has minimum requirements for executing a Java application
9) What is true about JRE(Java Runtime Environment)? (Choose 1)
a) Includes the compiler(javac) and the Java Virtual Machine(JVM)
b) Includes lang and util libraries like Java Archive (JAR).
c) Includes a variety of projects and tutorials to help beginners to develop apps
d) Contains and orchestrates the set of tools and minimum requirements for executing a Java application
10) Which of the following is a component of a basic Java program? (Choose 1)
a) main method
b) variable declaration
c) import statements
d) all of the above
11) Given the following class declarations, which of the following variants can be a way to compile and run them? (Choose
2)
*Assume the file containing the classes is called [Link]

Page 2 of 23
a) java Driver
b) javac *.java
java Driver
c) javac [Link]
java Driver
d) javac *.java
java Car

12) Which of the next class names are correct according to the Java conventions ?(Choose 2)
a) TestClass
b) 2BugNet
c) Watherbottle
d) SnakePart2
e) snake
13) Which of next variable names are correct, according to the Java convention? (Choose 1)
a) variableName
b) variable Name
c) 1variableName
d) variablename
14) Which of the following are reserved/key words in Java? (Choose 3)
a) new
b) next
c) if

Page 3 of 23
d) return
e) back
15) Operator “+” can be used with which of the following types? (Choose 2)
a) numeric
b) String
c) boolean
d) array
16) Which of the following is a correct way to comment code in Java? (Choose 2)
a) // this is some code
b) // this is some
code
c) /** this is some
code */
d) /* this is some */ code
17) Which of the following are part of the [Link] package? (Choose 3)
a) Math
b) Random
c) Object
d) String
e) Scanner
18) What should be inserted instead of //line1 for the following code to work? (Choose 1)
//line1
class Test{
public static void main(String[] args) {
Random rand = new Random();
[Link]([Link]([Link](100)));
}
}
a) import [Link].*
b) import [Link]
import [Link]
c) import [Link]
d) import [Link]

Page 4 of 23
19) Default value for a member float variable is: (Choose 1)
a) 0.0
b) 0.0f
c) 0
d) false
20) Which one of the following statement is correct? (Choose 1)
a) The ‘try’ block should be followed by a ‘catch’ block.
b) The ‘try’ block should be followed by a ‘finally’ block.
c) The ‘try’ block should be followed by either a ‘catch’ block or a ‘finally’ block.
d) The ‘try’ block should be followed by at least two ‘catch’ blocks.
21) What is the result of the following code? (Choose 1)
public class Hello {
String title;
int value;
public Hello() {
title += " World";
}
public Hello (int value) {
[Link] = value;
title = "Hello";
Hello ();
}
public static void main(String[] args){
Hello c = new Hello(5);
[Link]([Link]);
}
}
a) Hello
b) Hello World
c) Compilation fails.
d) Hello World 5

22) A constructor can: (Choose 1)

Page 5 of 23
a) Initialize instance variables.
b) When overloaded, can have identical argument lists.
c) When overloaded, are selected by number, types and order of types of parameters.
d) a and c.
23) Given following classes and declarations, which of the statements are true? (Choose 3)

public class Super {


private int i;
public void fly(){ }
public void gravity(){ }
}

class Sub extends Super {


public int j;
public void gravity() { }
}

//declarations
Super s = new Super();
Sub sb = new Sub();

a) The Sub class is a legal subclass of Super.


b) The statement [Link](); is legal.
c) The statement s.j = 5; is legal.
d) The statement [Link](); is legal.
e) The statement sb.i = 3; is legal.

24) Which of the following statements are true? (Choose 1)


a) Private methods cannot be overridden in subclasses.
b) A subclass can override any method in a non-final superclass.
c) The parameter list of an overriding method must be a subset of the parameter list of the method that it is
overriding.
d) The overriding method can have a different return value than the overridden method.

Page 6 of 23
25) Given classes A, B and C, where B extends A and C extends B and where all classes implement the instance method void
doIt(). How can the doIt() method in A be called from an instance method in C? (Choose 1)
a) DoIt();
b) [Link]();
c) ((A) this).doIt();
d) It is not possible.

26) What would be the result of attempting to compile and run the following code? (Choose 1)
public class MyClass {
public static void main(String[] args) {
C c = new C();
[Link]([Link](13,29));
} }
class A {
int max(int x, int y) { if(x > y) return x; else return y; }
}
class B extends A {
int max(int x, int y) { return [Link](y,x) – 10 ; }
}
class C extends B {
int max(int x, int y) { return [Link](x+10, y+10) ; }
}
a) The code will fail to compile, since the max() method in B passes the arguments to the calling method in the
wrong order.
b) The code will fail to compile, owing to a call to a max() method being ambiguous.
c) The code will compile and will print 13 when run.
d) The code will compile and will print 23 when run.
e) The code will compile and will print 29 when run.
f) The code will compile and will print 39 when run.

27) Even when an object is not initialized, a static variable can be accessed (Choose 1)
a) True

Page 7 of 23
b) False
28) A static variable is common to all objects of the class. (Choose 1)
a) True
b) False
29) In Java, exceptions are divided into what categories? (Choose 2)
a) Checked
b) Throwable
c) Unthrowable
d) Unchecked
30) Exceptions can be caught or rethrown to a calling method. (Choose 1)
a) True
b) False
31) If you throw an exception in your code, then you must declare it using which keyword in your method declaration?
(Choose 1)
a) throw
b) throws
c) catch
d) try

32) What is the result? (Choose 1)


public class Test {
public static void main(String [] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;
if ((x == 4) && !b2 )
[Link]("1 ");
[Link]("2 ");
if ((b2 = true) && b1)
[Link]("3 ");
}
}

Page 8 of 23
a) 2
b) 3
c) 1 2
d) 2 3
33) Round and pow are methods of which package? (Choose 1)
a) util package
b) math package
c) lang package
d) net package

34) What is the result? (Choose 1)


String str1,str2,str3;
str1="1";
str2="0";
str3="100";
int a,b,c;
str1=str1+str2;
a=[Link](str1);
b=[Link](str3);
c=a+b;
[Link](""+c);

a) 110
b) 101
c) 102
d) 103

35) Instantiating a class results a: (Choose 1)


a) Object
b) Method
c) Constructor
d) Destructor
36) Integer a = new Integer(2);

Page 9 of 23
Integer b = new Integer(2);
What is returned when you execute the a==b and [Link](b) statements? (Choose 1)
a) true true
b) true false
c) false false
d) false true
37) What will be displayed after the next code is run? (Choose 1)
int value = 21;
int a = ++value;
int b = value;
int c = value++;
if(a == b && a == c) {
if(b == c) {
a = ++value;
} else {
a = ++c;
}
}
[Link](a);

a) 22
b) 23
c) 24
d) 25

38) What will be displayed? (Choose 1)


public static void main(String[] args) {
String string = "123456789";
[Link]([Link]("4"), [Link]("8"));
[Link]("89");
[Link](string);
}
a) 456789

Page 10 of 23
b) 4567889
c) 5678
d) 123456789

39) What will be displayed? (Choose 1)


String a = "Hello World";
String b = new String("Hello World");
[Link](a == b);
[Link]([Link](b));
[Link]([Link](b));
a) true
true
0
b) false
true
0
c) true
false
0
d) false
false
1
40) What is a loop ? (Choose 2)
a) A segment of code to be run a specified amount of times
b) A new type of Applet
c) A new type of data
d) A statement that allows code to be executed repeatedly
41) Which of the following are primitive data types? (Choose 3)
a) byte
b) char
c) Integer
d) long
e) String

Page 11 of 23
42) The default segment of a switch is executed: (Choose 1)
a) Always
b) When any case is matched
c) When no case is matched
d) Never
43) Who defines the common variables and methods of a set of objects? (Choose 1)
a) Object

b) Class

c) Function

d) Attribute

44) Which of the following is a property of object oriented programming? (Choose 1)

a) Attribute

b) Function

c) Method

d) Polymorphism

45) Which of the following is the process of removing errors found in the program? (Choose 1)

a) Editing

b) Compiling

c) Debugging

d) Running

46) Which symbol is used to denote a multi-line comment? (Choose 1)


a) //

b) /* */

c) { }

d) <>

47) Which of the following statements is false? (Choose 1)

Page 12 of 23
a) A subclass is generally larger than its superclass.

b) A superclass object is a subclass object.

c) The class following the extends keyword in a class declaration is the direct superclass of the class being
declared.
d) Java uses interfaces to provide the benefits of multiple inheritance.

48) Inheritance is also known as the: (Choose 1)


a) “knows-a” relationship.

b) “has-a” relationship.

c) “uses-a” relationship.

d) “is-a” relationship.

49) Which of the following keywords allows a subclass to access a superclass method even when the subclass has
overridden the superclass method? (Choose 1)
a) base

b) public

c) this

d) super

50) Which superclass members are inherited by all subclasses of that superclass? (Choose 1)
a) private instance variables and methods.

b) protected instance variables and methods.

c) private constructors.

d) protected constructors.

51) Consider the classes below, declared in the same file: (Choose 1)

class A {
int a;
public A() { a = 7; }
}

Page 13 of 23
class B extends A {
int b;
public B() { b = 8; }
}
Which of the statements below is false?

a) Both variables a and b are instance variables.

b) After the constructor for class B executes, the variable a will have the value 7.

c) After the constructor for class B executes, the variable b will have the value 8.

d) A reference of type A can be treated as a reference of type B.

52) Given below the sample code, what will be its output? (Choose 1)
class Hotel {
public int bookings=2;
public void book() { bookings++; }
}
public class SuperHotel extends Hotel {
public void book() {bookings--; }
public void book(int size) {
book();
[Link]();
bookings += size;
}
public static void main(String args[]) {
SuperHotel Shotel = new SuperHotel();
[Link](2);
[Link]([Link]);
}
}
a) No Output
b) 4
c) Compile error
d) 2

Page 14 of 23
53) A constructor cannot: (Choose 1)
a) Be overloaded with more parameters.

b) Initialize variables to their defaults.

c) Specify return types or return values.

d) Have the same name as the class.

54) A package is: (Choose 1)


a) A directory structure used to organize classes and interfaces.

b) A mechanism for software reuse

c) A group of related classes and interfaces

d) All of the above

55) What will be displayed after the following code is run? (Choose 1)
public class Test {
static char a;
static String b;
static double c;
public static void main(String[] args) {
[Link]("[" + b + ":" + a + ":" + c + "]");
}
}
a) [null:null:0]

b) [null::0.0]

c) [:null:0.0]

d) [::0]

56) What will be displayed after the following code is run?(Choose 1)

public class Test {


static final int test = 100;
Page 15 of 23
public static void print(){
[Link](test);
}
public int print(int nr){ //line1
print();
test *=nr; //line2
return test;
}
public static void main(String[] args) {
Test o = new Test();
[Link]([Link](30));
}
}

a) Compilation error at line1

b) Compilation error at line2

c) 100

3000

d) 3000

100

57) What will display the following code: (Choose 1)


import [Link].*;
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
[Link]("lily");
[Link]("rose");
for(Iterator<String> it = [Link](); [Link]();){

[Link]([Link]());

Page 16 of 23
a) lily rose
b) rose lily
c) lily
d) Compilation error

58) What will display the next code? (Choose 1)

int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

for(int i = 0; i < 10; i++){

if(a[i] % 2 ==1) {

[Link](a[i] + " ");

a) 1 2 3 4 5 6 7 8 9 10
b) 1 3 5 7 9

c) 2 4 6 8 10

d) nothing

59) What will display the next code? (Choose 1)

boolean a = true;
boolean b = false;
boolean c = true;

if(a && b) {
[Link]("1 ");
}
if(a && c){
[Link]("2 ");
}
if(a || b){

Page 17 of 23
[Link]("3 ");
}
if(!b && c){
[Link]("4 ");
}
if(!c || b){
[Link]("5 ");
}

a) 1 2 3 4 5

b) 1 5

c) 2345

d) 2 3 4

60) Which option will display the following text:(Choose 1)

”Mihai este cel mai bun din clasa.

Media mea este 9.3 dar voi lua 10.”

a) [Link](“%d este cel mai bun din clasa.%dMedia mea este %s dar voi lua %f”, “Mihai”, 9.3, 10);

b) [Link](“%a este cel mai bun din clasa.%nMedia mea este %c dar voi lua %d”, “Mihai”, 9.3, 10);

c) [Link](“%s este cel mai bun din clasa.%nMedia mea este %x dar voi lua %f”, “Mihai”, 9.3, 10);

d) [Link](“%s este cel mai bun din clasa.%nMedia mea este %f dar voi lua %d”, “Mihai”, 9.3, 10);

61) What will display the next code? (Choose 1)

int value = 20;

int a = value ++;

int b = ++ a;

int c = a + value ++;

Page 18 of 23
[Link](a + " " + b + " " + --c + " " + value);

a) 21 21 40 20

b) 20 21 42 22

c) 21 21 41 22

d) 21 21 43 22

62) What will be displayed after the following code is run? (Choose 1)

public class Test {


final int testNumber = 10; //line1

public static void main(String[] args){


Test test = new Test(); // line2
[Link] ++; //line3
[Link]([Link]);
}
}
a) Compilation error at //line1

b) Compilation error at //line2

c) Compilation error at //line3

d) 11

63) What will be displayed after the following code is run? (Choose 1)

class SuperTest {
public final void testMethod(){ // line1
[Link](“Super!”);
}
}
class Test extends SuperTest {
public void testMethod(){ // line2
Page 19 of 23
[Link](“Test!”);
}
public static void main(String[] args){
Test test = new Test();
[Link]();
}
}
a) Compilation error at //line1

b) Compilation error at //line2

c) Super

d) Test

64) What will display the following code? (Choose 1)

int[] numbers = new int[3];


Arraylist<Integer> list = new ArrayList<Integer>();
numbers[1] = 10;
numbers[2] = 11;
[Link](9);
[Link](10);
[Link](0);
[Link](0);
[Link](9);
[Link](10);
[Link](11);
[Link](0);
[Link](numbers);
[Link](list);

a) hashcode in hexadecimal form


hashcode in hexadecimal form

b) hashcode in hexadecimal form


[10, 11]
Page 20 of 23
c) 0 10 11
[10, 11]

d) 10, 11
[10, 11]

65) What should display the code below? (Choose 1)


List<String> list = new ArrayList<String>();
[Link]("lily");
[Link]("rose");
[Link]();
[Link]("lily");
[Link]("rose");
[Link]("dandelion");
[Link](0);
[Link](2, "lily");

a) Runtime error

b) [lily, rose, dandelion]

c) [lily, rose]

d) [rose, dandelion, lily]

66) You can display the reversed list with an enhanced for using: (Choose 1)
a) ListIterator
b) Iterator
c) This is not possible
d) This can be done only with a classic for
67) Which of the following statements are correct? (Choose 2)
a) int a = 2f;
b) double b = 2.0;
c) int c = 3.5;
d) int d = 'a';
e) short e = "hello";
68) Methods that are marked protected can be called in any subclass of that class. (Choose 1)

Page 21 of 23
a) True

b) False
69) What will be displayed after the following code snippet is run? (Choose 1)

int i = 0, j = 0;
while( i < 10) {
System. [Link](“ ” + i);
i++;
}
[Link](“”);
do {
System. [Link](“ ” + j);
j++;
} while(j < 10);

a) 0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
b) 0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9 10
c) 0 1 2 3 4 5 6 7 8 9 10
0123456789
d) 0 1 2 3 4 5 6 7 8 9
0123456789

70) What will be displayed after the following code snippet is run? (Choose 1)

int a = 0;
for (int i = 0; i < 200; i += 10) {
if (a %10 == 0) {
a++;
continue;
}
if(i == 160) break;
a++;

Page 22 of 23
}
[Link](a);
a) 15
b) 16
c) 19
d) 20

71) What is the difference between lists and arrays? (Choose 1)


a) A list can memorize primitive types
b) An array can memorize references
c) A list uses methods to modify its content

72) Which of the following means that in order for the conditional to happen, either x must be less than 3 or y must be
greater than or equal to 4? (Choose 1)

a) if ((x < 3) || (y >= 4))

b) if ((x > 3) || (y <= 4))

73) In a 'for' loop, what section of the loop is not included in the parentheses that follow the "for" keyword? (Choose 1)
a) Loop Body
b) Initialization

c) Counter increase / decrease

d) Evaluation

74) Which of the following visibility modifiers can be used to access a class from a different package? (Choose 2)
a) public
b) private
c) protected
d) default (package-mode)

75) What is true about enhanced for? (Choose 1)


a) Can only be used in combination with arrays
b) Can only be used in combination with Lists
c) Can be used with both of the above
Page 23 of 23

You might also like