CCE107L WRITTEN TEST

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Identify the output of the following program. String str = "Hellow"; System.out.println(str.indexOf('t));

-1

Find the output of the following program. public class Solution{ public static void main(String[] args){ byte x = 127; x++; x++; System.out.print(x); } }

-127

Predict the output of following Java Program class Test { public static void main(String args[]) { int x = -4; System.out.println(x>>1); int y = 4; System.out.println(y>>1); } }

-2 2

Which of the following is a valid long literal?

0xnf029L

Predict the output of the following program. class Test { public static void main(String[] args) { String obj1 = new String("geeks"); String obj2 = new String("geeks"); if(obj1.hashCode() == obj2.hashCode()) System.out.println("hashCode of object1 is equal to object2"); if(obj1 == obj2) System.out.println("memory address of object1 is same as object2"); if(obj1.equals(obj2)) System.out.println("value of object1 is equal to object2"); }

HashCode of object1 is equal to object2 value of object1 is equal to object2

In which memory a String is stored, when we create a string using new operator?

Heap memory

What is Runnable?

Interface

What should be the execution order, if a class has a method, static block, instance block, and constructor, as shown below? public class First_C { public void myMethod() { System.out.println("Method"); } { System.out.println(" Instance Block"); } public void First_C() { System.out.println("Constructor "); } static { System.out.println("static block"); } public static void main(String[] args) { First_C c = new First_C(); c.First_C(); c.myMethod(); } }

Static block, instance block, constructor, and method

When an array is passed to a method, what does the method receive?

The reference of the array

What is meant by the classes and objects that dependents on each other?

Tight Coupling

The \u0021 article referred to as a

Unicode escape sequence

Exception created by try block is caught in which block

catch

It refers to the array of arrays, where each element is considered as an array in itself.

multidimensional array

Which of the following creates a List of 3 visible items and multiple selections abled?

new List(3, true)

The kind of methods in which already provided, written, and defined in Java class libraries.

predefined methods

Determine the output of the following code fragments: public class Main { public static void main(String args[]) { int arr[][] = new int[4][]; arr[0] = new int[1]; arr[1] = new int[2]; arr[2] = new int[3]; arr[3] = new int[4]; int i, j, k = 0; for (i = 0; i < 4; i++) { for (j = 0; j < i + 1; j++) { arr[i][j] = k; k++; } } for (i = 0; i < 4; i++) { for (j = 0; j < i + 1; j++) { System.out.print(" " + arr[i][j]); k++; } System.out.println(); } } }

0 1 2 3 4 5 6 7 8 9

Find the value of A[1] after execution of the following program. int[] A = {0,2,4,1,3}; for(int i = 0; i < a.length; i++){ a[i] = a[(a[i] + 3) % a.length]; }

1

Identify the correct restriction on static methods. They must access only static data They can only call other static methods. They cannot refer to this or super.

1, 2 and 3

Find the output of the following program. public class Solution{ public static void main(String[] args){ int[] x = {120, 200, 016}; for(int i = 0; i < x.length; i++){ System.out.print(x[i] + " "); } } }

120 200 14

Find the output of the following code. int Integer = 24; char String = 'I'; System.out.print(Integer); System.out.print(String);

24 I

ab cd ef gh ij kl

25

Find the output of the following code. Public class Solution{ Public static void main(String... argos){ Int x = 5; x * = (3 + 7); System.out.println(x);

50

Find the output of the following code. Public class Solution{ Public static void main(String args[]){ Int i; for(i = 1; i < 6; i++){ if(i > 3) continue; } System.out.println(i); } }

6

What will be the output of the following program? public class MyFirst { public static void main(String[] args) { MyFirst obj = new MyFirst(n); } static int a = 10; static int n; int b = 5; int c; public MyFirst(int m) { System.out.println(a + ", " + b + ", " + c + ", " + n + ", " + m); } // Instance Block { b = 30; n = 20; } // Static Block static { a = 60; } }

60, 30, 0, 20, 0

What will be the output of the following program? public class Test { public static void main(String[] args) { int count = 1; while (count <= 15) { System.out.println(count % 2 == 1 ? "***" : "+++++"); ++count; } // end while } // end main }

8 times *** and 7 times +++++

Predict the output of the following program. class Test { public static void main(String[] args) { Double object = new Double("2.4"); int a = object.intValue(); byte b = object.byteValue(); float d = object.floatValue(); double c = object.doubleValue(); System.out.println(a + b + c + d ); } }

8.800000095367432

What is the output of the following Java program? Class Test { public static void main (String [] args) { int x = 0; int y = 0; for (int z = 0; z < 5; z++) { if((++x > 2) || (++y > 2)) { x++; } } System.out.println( x + " " + y); } }

82

Which option is false about the final keyword?

A final class cannot extend other classes.

Identify the corrected definition of a package.

A package is a collection of classes and interfaces

Identify the infinite loop.

All of the above

What do you mean by chained exceptions in Java?

An exception caused by other exceptions

What do you mean by nameless objects?

An object that has no reference.

Which of the following is an immediate subclass of the Panel class?

Applet class

Which of the following exception is thrown when divided by zero statement is executed?

ArithmeticException

It refers to a group together to perform a certain task or operation.

Block code

Identify the correct way of declaring constructor. Public class Solution {}

Both A and B

Which of the following option leads to the portability and security of Java?

Bytecode is executed by JVM

What will be the output of the following program? public class Test2 { public static void main(String[] args) { StringBuffer s1 = new StringBuffer("Complete"); s1.setCharAt(1,'i'); s1.setCharAt(7,'d'); System.out.println(s1); } }

Cimpletd

Identify the interface which is used to declare core methods in java?

Collection

Find the output of the following program. public class Solution{ public static void main(String[] args){ short x = 10; x = x * 5; System.out.print(x); } }

Compile error

Determine the output of the following code fragments: class Test { public static void main(String args[]) { int arr[2]; System.out.println(arr[0]); System.out.println(arr[1]); } }

Compiler Error

Predict the output of following Java program. class Test { public static void main(String[] args) { for(int i = 0; 0; i++) { System.out.println("Hello"); break; } } }

Compiler Error

Which of these classes are the direct subclasses of the Throwable class?

Error and Exception class

What does the expression float a = 35 / 0 return?

Infinity

What is the variables declared in a class for the use of all methods of the class called?

Instance variables

Which of the following is true about the anonymous inner class?

It has no class name

What is the use of the intern() method?

It returns the existing string from memory

Which of the following is used to find and fix bugs in the program?

JDB

_____ is used to find and fix bugs in the Java programs.

JDB

Which of the following tool is used to generate API documentation in HTML format from doc comments in source code?

Javadoc tool

Which of the following is FALSE about arrays in Java?

Length of array can be changed after creation of array

An interface with no fields or methods is known as a ______.

Marker Interface

What is the output of following Java codes? class Test { public static void main (String[] args) { int arr1[] = {1, 2, 3}; int arr2[] = {1, 2, 3}; if (arr1 == arr2) System.out.println("Same"); else System.out.println("Not same"); } }

Not Same

What is the output of the following Java codes? public class Main { public static void main(String args[]) { String x = null; giveMeAString(x); System.out.println(x); } static void giveMeAString(String y) { y = "GeeksQuiz"; } }

Null

Identify what can directly access and change the value of the variable res. Package com.mypackage; Public class Solution{ Private int res = 100; }

Only Solution class

This method can be called from anywhere, either other class, or different packages (files) for as long as you import the class.

Public

Where does the system stores parameters and local variables whenever a method is invoked?

Stack

Identify the incorrect Java feature.

Use of pointers

Which of the following is not a Java features?

Use of pointers

In which process, a local variable has the same name as one of the instance variables?

Variable Shadowing

Predict the output of the following program. class Test { public void demo(String str) { String[] arr = str.split(";"); for (String s : arr) { System.out.println(s); } } public static void main(String[] args) { char array[] = {'a', 'b', ' ', 'c', 'd', ';', 'e', 'f', ' ', 'g', 'h', ';', 'i', 'j', ' ', 'k', 'l'}; String str = new String(array); Test obj = new Test(); obj.demo(str); } }

ab cd ef gh ij kl

It refers to the collection of data with a similar data type.

array

It refers to the location of each element in the array.

array index

It refers to the length of the array or the allocation of memory for the array. a.

array size

Identify the output of the following program. String str = "abcde"; System.out.println(str.substring(1, 3));

bc

It is a conditional structure that performs different processes based on whether a certain condition is true or false.

branching or selection

Which of the following is a valid declaration of a char?

char ch = '\utea';

Select the valid statement.

char[] ch = new char[5]

class Main { public static void main(String args[]) { int t; System.out.println(t); } }

compiler error

It specifies a statement to run if there is no match found within the case.

default keyword

It is similar to the while loop, but the body of this loop is executed once before the expression is executed.

do while loop

It refers to the condition set by the user or programmer.

expression

It uses a Boolean variable and is used primarily to control the logical flow of the codes or program.

flag variable

Which of the following for loop declaration is not valid?

for ( int i = 99; i >= 0; i / 9 )

Which method of the Class.class is used to determine the name of a class represented by the class object as a String?

getName()

Predict the output of the following program. class Test { public static void main(String[] args) { StringBuffer a = new StringBuffer("geeks"); StringBuffer b = new StringBuffer("forgeeks"); a.delete(1,3); a.append(b); System.out.println(a); } }

gksforgeeks

class Test { public static void swap(Integer i, Integer j) { Integer temp = new Integer(i); i = j; j = temp; } public static void main(String[] args) { Integer i = new Integer(10); Integer j = new Integer(20); swap(i, j); System.out.println("i = " + i + ", j = " + j); } }

i= 10; j = 20;

It determines if the condition from the block of code is false.

if statement

Which keyword is used for accessing the features of a package?

import

What is the return type of the hashCode() method in the Object class?

int

Select the valid statement to declare and initialize an array.

int[] A = {1, 2, 3}

Which package contains the Random class?

java.util package

It executes a sequence of statements repeatedly as long a condition is still true and ends once the condition becomes false.

looping or iteration

It is composed of the method header and the method body.

method body

It is known as the method signature, where all the action of a method takes place. It contains the legal Java statements that implement the method.

method body

It provides information about the method to the compiler, and to other classes and objects.

method declaration

Predict the output of the following program. class Test implements Cloneable { int a; Test cloning() { try { return (Test) super.clone(); } catch(CloneNotSupportedException e) { System.out.println("CloneNotSupportedException is caught"); return this; } } } class demo { public static void main(String args[]) { Test obj1 = new Test(); Test obj2; obj1.a = 10; obj2 = obj1.cloning(); obj2.a = 20; System.out.println("obj1.a = " + obj1.a); System.out.println("obj2.a = " + obj2.a); } }

obj1.a = 10 obj2.a = 20

Identify the output of the following program. Public class Test{ Public static void main(String argos[]){ String str1 = "one"; String str2 = "two"; System.out.println(str1.concat(str2)); } }

onetwo

A kind of method can only be called inside the class.

private

The type of method that can only be called inside the class.

private

It refers only to the class or subclass where it is built of can call the method.

protected

Identify the prototype of the default constructor. Public class Solution {}

public Solution( )

It uses special value, and it is called another name for a trailer value.

sentinel

It refers to the straightforward program execution, in which the codes are executed one after the other.

sequence

Identify the modifier which cannot be used for constructor.

static

It is used to evaluate an expression. The value of the expression will be compared to the values of each case structure. If their match is found, the associated block of code is performed.

switch statement

It's a type of method written by the user or programmer, which is modified according to the requirement.

user-defined methods

It is used to specify the block of code and determine if a specified condition is true.

valid identifier


Ensembles d'études connexes

Tema 2 - Las Ciencias y Las Tecnologías (Contexto 3)

View Set

Operating systems final Multiple choice

View Set

CIS 155 OPERATING SYSTEMS FINAL QUESTIONS

View Set

Chapter 44 Biliary Disorders Prep U

View Set

Modern Database Management - Final Study

View Set

Unit 4 EXAM- America Becomes a World Power Review

View Set