first assessment test questions with answers

33
Assessment Test 1 Nocetyps Technologies 1.Which of the following special symbol allowed in a variable name? A. * (asterisk) B. | (pipeline) C. - (hyphen) D. _ (underscore) Answer & Explanation Answer: Option D Explanation: Variable names in C are made up of letters (upper and lower case) and digits. The underscore character ("_") is also permitted. Names must not begin with a digit. Examples of valid (but not very descriptive) C variable names: => foo => Bar => BAZ => foo_bar => _foo42 => _ => QuUx 2. A default catch block catches A. all thrown objects B. no thrown objects C. any thrown object that has not been caught by an earlier catch block D. all thrown objects that have been caught by an earlier catch block Answer & Explanation Answer: Option C Explanation: 3.How would you round off a value from 1.66 to 2.0? A. ceil(1.66) B. floor(1.66) C. roundup(1.66) D. roundto(1.66)

Upload: syed-tameem-azhar

Post on 15-Oct-2014

97 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: First Assessment Test Questions With Answers

Assessment Test 1 Nocetyps Technologies

1.Which of the following special symbol allowed in a variable name?

A. * (asterisk) B. | (pipeline)C. - (hyphen) D. _ (underscore)Answer & ExplanationAnswer: Option D

Explanation:

Variable names in C are made up of letters (upper and lower case) and digits. The underscore character ("_") is also permitted. Names must not begin with a digit.

Examples of valid (but not very descriptive) C variable names:=> foo => Bar => BAZ => foo_bar => _foo42 => _ => QuUx

2. A default catch block catches

A. all thrown objectsB. no thrown objectsC. any thrown object that has not been caught by an earlier catch blockD. all thrown objects that have been caught by an earlier catch blockAnswer & ExplanationAnswer: Option C

Explanation:

3.How would you round off a value from 1.66 to 2.0?

A. ceil(1.66) B. floor(1.66)C. roundup(1.66) D. roundto(1.66)Answer & ExplanationAnswer: Option A

Explanation:

/* Example for ceil() and floor() functions: */

#include<stdio.h>#include<math.h>

Page 2: First Assessment Test Questions With Answers

int main(){ printf("\n Result : %f" , ceil(1.44) ); printf("\n Result : %f" , ceil(1.66) ); printf("\n Result : %f" , floor(1.44) ); printf("\n Result : %f" , floor(1.66) );

return 0;}// Output:// Result : 2.000000// Result : 2.000000// Result : 1.000000// Result : 1.000000

4.How many times "Hello" is get printed?

#include<stdio.h>int main(){ int x; for(x=-1; x<=10; x++) { if(x < 5) continue; else break; printf("Hello"); } return 0;}A. Infinite times B. 11 timesC. 0 times D. 10 timesAnswer & ExplanationAnswer: Option C

5.Which of the following is not logical operator?

A. & B. &&C. || D. !Answer & ExplanationAnswer: Option A

Explanation:

Bitwise operators:& is a Bitwise AND operator.

Logical operators:&& is a Logical AND operator.|| is a Logical OR operator.

Page 3: First Assessment Test Questions With Answers

! is a NOT operator.So, '&' is not a Logical operator.

6.In mathematics and computer programming, which is the correct order of mathematical operators ?

A. Addition, Subtraction, Multiplication, DivisionB. Division, Multiplication, Addition, SubtractionC. Multiplication, Addition, Division, SubtractionD. Addition, Division, Modulus, SubtractionAnswer & ExplanationAnswer: Option B

Explanation:

Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction).nemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. In other English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponentiation may be called either Indices, Powers or Orders, and since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BEDMAS, BIDMAS, BODMAS, BERDMAS, PERDMAS, and BPODMAS.

7.Which of the following cannot be checked in a switch-case statement?

A. Character B. IntegerC. Float D. enumAnswer & ExplanationAnswer: Option C

Explanation:

The switch/case statement in the c language is defined by the language specification to use an int value, so you can not use a float value.

switch( expression ){ case constant-expression1: statements 1; case constant-expression2: statements 2; case constant-expression3: statements3 ; ... ... default : statements 4;}

Page 4: First Assessment Test Questions With Answers

The value of the 'expression' in a switch-case statement must be an integer, char, short, long. Float and double are not allowed.

8.Evaluate the following expression: 3 >6&&7>4

A. True B. FalseAnswer & ExplanationAnswer: Option B

9.Point out the error, if any in the program.

#include<stdio.h>int main(){ int a = 10; switch(a) { } printf("This is c program."); return 0;}A. Error: No case statement specifiedB. Error: No default specifiedC. No ErrorD. Error: infinite loop occursAnswer & ExplanationAnswer: Option C

Explanation:

There can exists a switch statement, which has no case.

10.Point out the error, if any in the while loop.

#include<stdio.h>int main(){ int i=1; while() { printf("%d\n", i++); if(i>10) break; } return 0;}A. There should be a condition in the while loopB. There should be at least a semicolon in the whileC. The while loop should be replaced with for loop.D. No errorAnswer & Explanation

Page 5: First Assessment Test Questions With Answers

Answer: Option A

Explanation:

The while() loop must have conditional expression or it shows "Expression syntax" error.

11.Which of the following errors would be reported by the compiler on compiling the program given below?

#include<stdio.h>int main(){ int a = 5; switch(a) { case 1: printf("First");

case 2: printf("Second");

case 3 + 2: printf("Third");

case 5: printf("Final"); break;

} return 0;}A. There is no break statement in each case.B. Expression as in case 3 + 2 is not allowed.C. Duplicate case case 5:D. No error will be reported.Answer & ExplanationAnswer: Option C

Explanation:

Because, case 3 + 2: and case 5: have the same constant value 5.

12.Point out the error, if any in the while loop.

#include<stdio.h>int main(){ void fun(); int i = 1; while(i <= 5) { printf("%d\n", i); if(i>2) goto here;

Page 6: First Assessment Test Questions With Answers

}return 0;}void fun(){ here: printf("It works");}A. No Error: prints "It works"B. Error: fun() cannot be accessedC. Error: goto cannot takeover control to other functionD. No errorAnswer & ExplanationAnswer: Option C

Explanation:

A label is used as the target of a goto statement, and that label must be within the same function as the goto statement.

Syntax: goto <identifier> ;Control is unconditionally transferred to the location of a local label specified by <identifier>.

13.Point out the error, if any in the program.

#include<stdio.h> int main(){ int a = 10, b; b= a >=5 ? b=100: b=200; printf("%d\n", b); return 0;}A. 100 B. 200C. Error: L value required for b D. Garbage valueAnswer & ExplanationAnswer: Option C

Explanation:

Variable b is not assigned.

It should be like:

b = a >= 5 ? 100 : 200;

14.How will you free the memory allocated by the following program?

#include<stdio.h>#include<stdlib.h>#define MAXROW 3#define MAXCOL 4

Page 7: First Assessment Test Questions With Answers

int main(){ int **p, i, j; p = (int **) malloc(MAXROW * sizeof(int*)); return 0;}A. memfree(int p);B. dealloc(p);C. malloc(p, 0); D. free(p);Answer & ExplanationAnswer: Option D

Explanation:

15.Point out the error in the following program.

#include<stdio.h>#include<stdlib.h>

int main(){ int *a[3]; a = (int*) malloc(sizeof(int)*3); free(a); return 0;}A. Error: unable to allocate memoryB. Error: We cannot store address of allocated memory in aC. Error: unable to free memoryD. No errorAnswer & ExplanationAnswer: Option B

Explanation:

We should store the address in a[i]

16.To expose a data member to the program, you must declare the data member in the _____ section of the class

A. common B. exposedC. public D. unrestrictedE. userAnswer & ExplanationAnswer: Option C

17.A C++ program contains a function with the header int function(double d, char c). Which of the following function headers could be used within the same program?

A. char function(double d, char c)B. int function(int d, char c)C. both (a) and (b)D. neither (a) nor (b)

Page 8: First Assessment Test Questions With Answers

Answer & ExplanationAnswer: Option BExplanation:the compiler differentiates the functions with same name based on.I) no. Of arguments.Ii) type of arguments.The return type is not a taken into account in case of function overloading.Thus (A) is ruled out.

18.The feature in object-oriented programming that allows the same operation to be carried out differently, depending on the object, is_____

A. inheritance B. polymorphismC. overfunctioningD. overridingAnswer & ExplanationAnswer: Option B

Explanation:

19.The process of extracting the relevant attributes of an object is known as

A. polymorphismB. inheritanceC. abstractionD. data hidingAnswer & ExplanationAnswer: Option C

Explanation:

Abstraction is the process of extracting the relevant properties of an object while ignoring nonessential details. The extracted properties define a view of the object.

20. A function that is called automatically each time an object is destroyed is a

A. constructor B. destructorC. destroyer D. terminatorAnswer & ExplanationAnswer: Option B

Explanation:

1. Which of the following statements are TRUE about the .NET CLR?

It provides a language-neutral development & execution environment.It ensures that an application would not be able to access memory that it is not authorized to access.It provides services to run "managed" applications.The resources are garbage collected.It provides services to run "unmanaged" applications.

Page 9: First Assessment Test Questions With Answers

A. Only 1 and 2B. Only 1, 2 and 4C. 1, 2, 3, 4D. Only 4 and 5E. Only 3 and 4

Answer & ExplanationAnswer: Option C

Explanation:

2. Which of the following utilities can be used to compile managed assemblies into processor-specific native code?

A. gacutil B. ngenC. sn D. dumpbinE. ildasmAnswer & ExplanationAnswer: Option B

Explanation:

3. Which of the following components of the .NET framework provide an extensible set of classes that can be used by any .NET compliant programming language?

A. .NET class librariesB. Common Language RuntimeC. Common Language InfrastructureD. Component Object ModelE. Common Type SystemAnswer & ExplanationAnswer: Option A

Explanation:

No answer description available for this question. Let us discuss.

4. Which of the following jobs are NOT performed by Garbage Collector?

Freeing memory on the stack.Avoiding memory leaks.Freeing memory occupied by unreferenced objects.Closing unclosed database collections.Closing unclosed files.A. 1, 2, 3B. 3, 5C. 1, 4, 5D. 3, 4Answer & ExplanationAnswer: Option C

Page 10: First Assessment Test Questions With Answers

Explanation:

5. Which of the following constitutes the .NET Framework?

ASP.NET ApplicationsCLRFramework Class LibraryWinForm ApplicationsWindows Services

A. 1, 2B. 2, 3C. 3, 4D. 2, 5Answer & ExplanationAnswer: Option B

Explanation:

6. Which of the following assemblies can be stored in Global Assembly Cache?

A. Private AssembliesB. Friend AssembliesC. Shared AssembliesD. Public AssembliesE. Protected AssembliesAnswer & ExplanationAnswer: Option C

Explanation:

7. Which of the following is NOT a namespace in the .NET Framework Class Library?

A. System.ProcessB. System.SecurityC. System.ThreadingD. System.DrawingE. System.XmlAnswer & ExplanationAnswer: Option A

8.Which of the following statments are the correct way to call the method Issue() defined in the code snippet given below?

Page 11: First Assessment Test Questions With Answers

namespace College{ namespace Lib { class Book { public void Issue() { // Implementation code } } class Journal { public void Issue() { // Implementation code } } }}1)College.Lib.Book b = new College.Lib.Book(); b.Issue();2)Book b = new Book(); b.Issue();3)using College.Lib; Book b = new Book(); b.Issue();4)using College;Lib.Book b = new Lib.Book(); b.Issue();5)using College.Lib.Book; Book b = new Book(); b.Issue();A. 1, 3B. 2, 4C. 3D. 4, 5Answer & ExplanationAnswer: Option A

9) Which of the following statements is correct about a namespace in C#.NET?

A. Namespaces help us to control the visibility of the elements present in it.B. A namespace can contain a class but not another namespace.C. If not mentioned, then the name 'root' gets assigned to the namespace.D. It is necessary to use the using statement to be able to use an element of a namespace.

Page 12: First Assessment Test Questions With Answers

E. We need to organise the classes declared in Framework Class Library into different namespaces.Answer & ExplanationAnswer: Option A

10. Which of the following is absolutely neccessary to use a class Point present in namespace Graph stored in library?

A. Use fully qualified name of the Point class.B. Use using statement before using the Point class.C. Add Reference of the library before using the Point class.D. Use using statement before using the Point class.E. Copy the library into the current project directory before using the Point class.Answer & ExplanationAnswer: Option C

11)12. Code that targets the Common Language Runtime is known as

A. UnmanagedB. DistributedC. LegacyD. Managed CodeE. Native Code

Answer & Explanation

12) A class implements two interfaces each containing three methods. The class contains no instance data. Which of the following correctly indicate the size of the object created from this class?

A. 12 bytesB. 24 bytesC. 0 byteD. 8 bytesE. 16 bytesAnswer & ExplanationAnswer: Option B

13. Which of the following are parts of the .NET Framework?

The Common Language Runtime (CLR)The Framework Class Libraries (FCL)Microsoft Published Web ServicesApplications deployed on IISMobile ApplicationsA. Only 1, 2, 3B. Only 1, 2C. Only 1, 2, 4D. Only 4, 5

Page 13: First Assessment Test Questions With Answers

E. All of the aboveAnswer: Option D

14Which of the following statements are correct about the C#.NET code snippet given below?

int[ , ] intMyArr = {{7, 1, 3}, {2, 9, 6}};intMyArr represents rectangular array of 2 rows and 3 columns.intMyArr.GetUpperBound(1) will yield 2.intMyArr.Length will yield 24.intMyArr represents 1-D array of 5 integers.intMyArr.GetUpperBound(0) will yield 2.A. 1, 2B. 2, 3C. 2, 5D. 1, 4E. 3, 4Answer & ExplanationAnswer: Option A

15.Which one of the following statements is correct?

A. Array elements can be of integer type only.B. The rank of an Array is the total number of elements it can contain.C. The length of an Array is the number of dimensions in the Array.D. The default value of numeric array elements is zero.E. The Array elements are guaranteed to be sorted.Answer & ExplanationAnswer: Option D

16.A property can be declared inside a class, struct, Interface.

A. True B. FalseAnswer & ExplanationAnswer: Option A

17.A Student class has a property called rollNo and stu is a reference to a Student object and we want the statement stu.RollNo = 28 to fail. Which of the following options will ensure this functionality?

A. Declare rollNo property with both get and set accessors.B. Declare rollNo property with only set accessor.C. Declare rollNo property with get, set and normal accessors.D. Declare rollNo property with only get accessor.E. None of the aboveAnswer & ExplanationAnswer: Option D

Page 14: First Assessment Test Questions With Answers

18.Which of the following statements is correct about namespaces in C#.NET?

A. Namespaces can be nested only up to level 5.B. A namespace cannot be nested.C. There is no limit on the number of levels while nesting namespaces.D. If namespaces are nested, then it is necessary to use using statement while using the elements of the inner namespace.E. Nesting of namespaces is permitted, provided all the inner namespaces are declared in the same file.Answer & ExplanationAnswer: Option C

19.Which of the following is NOT an Integer?

A. CharB. ByteC. IntegerD. ShortE. LongAnswer & ExplanationAnswer: Option A

20.Which of the following is an 8-byte Integer?

A. CharB. LongC. ShortD. ByteE. IntegerAnswer & ExplanationAnswer: Option B

// note write proper comments in ur programms to make it more understandableQuestion 1)

Generate a random number (use rand())between 0 and 9 and let the user guess it. Exit when user guessed right.

answer)// Purpose: Generate a random number between 0 and 9 and let the user // guess it. Use a while loop. Exit when user guessed right.//

#include <iostream>// <cstdlib> is needed in order to use the rand().// For older compilers, use <stdlib.h>#include <stdlib.h>

Page 15: First Assessment Test Questions With Answers

using namespace std;

int main(){ int magic; // magic number int guess; // user's guess

cout << "I will come up with a magic number between 0 and 9 "; cout << "and ask you to guess it." << endl;

magic = rand()%10; // get a random number between 0 and 9 cout << "Enter your guess: "; cin >> guess;

while (guess != magic) // as long as guess is incorrect {

if(guess > magic) { cout << "Too big! Guess again..." << endl; } else // guess is less than magic {

cout << "Too small! Guess again..." << endl; } cin >> guess;

} cout << "You are RIGHT!" << endl;; return 0;}

question 2)

Write a program to delete n Characters from a given position in a given string.without using in built functions.

answer)#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h#include(string.h)void main(){char st[20],temp[20];int pos,i,j,ct=0,n;clrscr();printf("Enter the string:");gets(st);printf("\nEntre the index position:");scanf("%d",&pos);printf("\nEnter the no.of characters:");scanf("%d",&n);if(pos<=strlen(st)) {for(i=0;i<=strlen(st);i++) {

Page 16: First Assessment Test Questions With Answers

if(i==pos){for(j=0;st[i]!='\0';j++) // to store the 'st' in 'temp' from a giv pos{temp[j]=st[i];i++;}temp[j]='\0';i=pos;//to delete the 'n' char and after restore the temp in st.for(j=0;temp[j]!='\0';j++){ct++;if(ct>n){st[i]=temp[j];i++;}}st[i]='\0';}}printf("\n\nAfter deletion the string: %s",st);}elseprintf("\nSorry, we cannot delete from that position.");getch();}

question 3)write a program to calculate total salary the inputs of the program will be 1."Basic"-Basic Salary 2) Hra% House rent allowance percentage of basic

calculate monthly and annuall salary and also calculate tax for the annual salary it will be 5% of the annual salary

question 4)

Write A program to generate the following pyramid of digits, using nested loops. 1 2 3 4 5 6 7 8 910 11 12 13 14 15

answer

Page 17: First Assessment Test Questions With Answers

#include<stdio.h>#include<conio.h>int main(){ int i, j,n,k;printf("Enter Number Of rows");scanf("%d",&n) ;int Number=1; for(i = 0; i < n; i++) {

for(j = n-i; j >0; j--){ printf(" ");}for(k=0;k<=i;k++) { printf("%d",Number++); printf(" "); }printf("\n");

} getch(); return 0;}

question 5)Write a C program to merge two unsorted one dimensional arrays in descending orderWrite a program to merge two unsorted 1D arrays in descending orderNote: Define the sizes of each array as a constant i.e. your program should run for arrays of any size.

Answer

#include(stdio.h) // note '<' & '>' in place of '(' & ')' // size of the array is 20#define MAX 20int main(){ int f[MAX],s[MAX]; int m,n; // to read the size of two arrays int i,j,temp; clrscr(); printf("Enter the 1st array size(1-20) :"); scanf("%d",&m); printf("Enter the 2nd array size(1-20) :"); scanf("%d",&n); printf("\nEnter the 1st array elements:"); for(i=0; i< m; i++) scanf("%d",&f[i] );

printf("\nEnter the 2nd array elements:"); for(j=0; j< n; j++) scanf("%d", &s[j] );

for(j=0; j< n; j++) // to store 's' elements to 'f'

Page 18: First Assessment Test Questions With Answers

{ f[i]=s[ j]; i++; } printf("\nBefore descending, the merged array is:\n"); for(i=0; i< m+n; i++) printf("%5d",f[i] );

for(i=0; i< m+n; i++)// to arrange the 'f' elements in Descending oder { for(j=i; j< (m+n)-1; j++) { if(f[i]< f[ j+1]) { temp=f[i]; f[i]=f[ j+1]; f[ j+1]=temp; } } } printf("\nAfter descending, the merged array is:\n"); for(i=0; i< m+n; i++) printf("%5d",f[i] );getch(); return 0;}

question 6)Write a C program to Sort the list of integers using Bubble Sort

Answer#include(stdio.h) //note place '<' & '>' in place of '(' & ')'#include(conio.h)void bubble(int [ ], int); // func. declarationvoid main( ){ int a[10],n,i;clrscr();printf("Enter the no. of elements u want to fill:");scanf("%d",&n);printf("\nEnter the array elements:");for(i=0; i< n; i++)scanf("%d",&a[i]);

bubble(a,n); // calling functiongetch();}

void bubble(int b[], int no) // called function{int i,j,temp;for(i=0; i< no-1; i++){

Page 19: First Assessment Test Questions With Answers

for(j=0; j< no-i; j++){if(b[j]>b[j+1]){temp=b[j];b[j]=b[j+1];b[j+1]=temp;}}}printf("\nAfter sorting : ");for(i=0; i< no; i++)printf("%5d",b[i] );}

1. Which four options describe the correct default values for array elements of the types indicated?

int -> 0String -> "null"Dog -> nullchar -> '\u0000'float -> 0.0fboolean -> trueA. 1, 2, 3, 4 B. 1, 3, 4, 5C. 2, 4, 5, 6 D. 3, 4, 5, 6Answer & ExplanationAnswer: Option B

Explanation:

(1), (3), (4), (5) are the correct statements.

(2) is wrong because the default value for a String (and any other object reference) is null, with no quotes.

(6) is wrong because the default value for boolean elements is false

2.Which one of these lists contains only Java programming language keywords?

A. class, if, void, long, Int, continueB. goto, instanceof, native, finally, default, throwsC. try, virtual, throw, final, volatile, transientD. strictfp, constant, super, implements, doE. byte, break, assert, switch, includeAnswer & ExplanationAnswer: Option B

Explanation:All the words in option B are among the 49 Java keywords. Although goto reserved as a keyword in Java, goto is not used and has no function.

Page 20: First Assessment Test Questions With Answers

Option A is wrong because the keyword for the primitive int starts with a lowercase i.Option C is wrong because "virtual" is a keyword in C++, but not Java.ption D is wrong because "constant" is not a keyword. Constants in Java are marked static and final.Option E is wrong because "include" is a keyword in C, but not in Java.

3.Which will legally declare, construct, and initialize an array?

A. int [] myList = {"1", "2", "3"};B. int [] myList = (5, 8, 2);C. int myList [] [] = {4,9,7,0};D. int myList [] = {4, 3, 7};Answer & ExplanationAnswer: Option D

Explanation:

The only legal array declaration and assignment statement is Option DOption A is wrong because it initializes an int array with String literals.Option B is wrong because it use something other than curly braces for the initialization.Option C is wrong because it provides initial values for only one dimension, although the declared array is a two-dimensional array

4.Which is a valid keyword in java?

A. interface B. stringC. Float D. unsignedAnswer & ExplanationAnswer: Option A

Explanation:interface is a valid keyword.Option B is wrong because although "String" is a class type in Java, "string" is not a keyword.Option C is wrong because "Float" is a class type. The keyword for the Java primitive is float.Option D is wrong because "unsigned" is a keyword in C/C++ but not in Java.

5.You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?A. public B. privateC. protected D. transientAnswer & ExplanationAnswer: Option C

6.public class Outer

Page 21: First Assessment Test Questions With Answers

{ public void someOuterMethod() { //Line 5 } public class Inner { } public static void main(String[] argv) { Outer ot = new Outer(); //Line 10 } } Which of the following code fragments inserted, will allow to compile?

A. new Inner(); //At line 5B. new Inner(); //At line 10C. new ot.Inner(); //At line 10D. new Outer.Inner(); //At line 10Answer & ExplanationAnswer: Option AExplanation:Option A compiles without problem.Option B gives error - non-static variable cannot be referenced from a static context.Option C package ot does not exist.Option D gives error - non-static variable cannot be referenced from a static context.

7.public class Test { }What is the prototype of the default constructor?A. Test( ) B. Test(void)C. public Test( ) D. public Test(void)Answer & ExplanationAnswer: Option C

Explanation:Option A and B are wrong because they use the default access modifier and the access modifier for the class is public (remember, the default constructor has the same access modifier as the class).Option D is wrong. The void makes the compiler think that this is a method specification - in fact if it were a method specification the compiler would spit it out.

8.Which is the valid declarations within an interface definition?

A. public double methoda();B. public final double methoda();C. static void methoda(double d1);D. protected void methoda(double d1);Answer & ExplanationAnswer: Option A

Page 22: First Assessment Test Questions With Answers

Explanation:Option A is correct. A public access modifier is acceptable. The method prototypes in an interface are all abstract by virtue of their declaration, and should not be declared abstract.Option B is wrong. The final modifier means that this method cannot be constructed in a subclass. A final method cannot be abstract.Option C is wrong. static is concerned with the class and not an instance.Option D is wrong. protected is not permitted when declaring a method of an interface. See information below.Member declarations in an interface disallow the use of some declaration modifiers; you cannot use transient, volatile, or synchronized in a member declaration in an interface. Also, you may not use the private and protected specifiers when declaring members of an interface.

9.Which one is a valid declaration of a boolean?

A. boolean b1 = 0;B. boolean b2 = 'false';C. boolean b3 = false;D. boolean b4 = Boolean.false();E. boolean b5 = no;Answer & ExplanationAnswer: Option C

Explanation:A boolean can only be assigned the literal true or false.10.Which is a valid declarations of a String?

A. String s1 = null;B. String s2 = 'null';C. String s3 = (String) 'abc';D. String s4 = (String) '\ufeed';Answer & ExplanationAnswer: Option A

Explanation:Option A sets the String reference to null.Option B is wrong because null cannot be in single quotes.Option C is wrong because there are multiple characters between the single quotes ('abc').Option D is wrong because you can't cast a char (primitive) to a String (object).

11.What is the numerical range of a char?A. -128 to 127 B. -(215) to (215) - 1C. 0 to 32767 D. 0 to 65535Answer & ExplanationAnswer: Option DExplanation:A char is really a 16-bit integer behind the scenes, so it supports 216 (from 0 to 65535) values.

Page 23: First Assessment Test Questions With Answers

12.public void foo( boolean a, boolean b){ if( a ) { System.out.println("A"); /* Line 5 */ } else if(a && b) /* Line 7 */ { System.out.println( "A && B"); } else /* Line 11 */ { if ( !b ) { System.out.println( "notB") ; } else { System.out.println( "ELSE" ) ; } } }A. If a is true and b is true then the output is "A && B"B. If a is true and b is false then the output is "notB"C. If a is false and b is true then the output is "ELSE"D. If a is false and b is false then the output is "ELSE"Answer & ExplanationAnswer: Option C

Explanation:Option C is correct. The output is "ELSE". Only when a is false do the output lines after 11 get some chance of executing.Option A is wrong. The output is "A". When a is true, irrespective of the value of b, only the line 5 output will be executed. The condition at line 7 will never be evaluated (when a is true it will always be trapped by the line 12 condition) therefore the output will never be "A && B".Option B is wrong. The output is "A". When a is true, irrespective of the value of b, only the line 5 output will be executed.Option D is wrong. The output is "notB".

13.switch(x) { default: System.out.println("Hello"); }Which two are acceptable types for x?bytelongcharfloatShortLongA. 1 and 3 B. 2 and 4C. 3 and 5 D. 4 and 6Answer & ExplanationAnswer: Option A

Page 24: First Assessment Test Questions With Answers

Explanation:Switch statements are based on integer expressions and since both bytes and chars can implicitly be widened to an integer, these can also be used. Also shorts can be used. Short and Long are wrapper classes and reference types can not be used as variables.

14.public void test(int x) { int odd = 1; if(odd) /* Line 4 */ { System.out.println("odd"); } else { System.out.println("even"); } }

Which statement is true?A. Compilation fails.B. "odd" will always be output.C. "even" will always be output.D. "odd" will be output for odd values of x, and "even" for even values.Answer & ExplanationAnswer: Option A

Explanation:

The compiler will complain because of incompatible types (line 4), the if expects a boolean but it gets an integer.

15.public class While { public void loop() { int x= 0; while ( 1 ) /* Line 6 */ { System.out.print("x plus one is " + (x + 1)); /* Line 8 */ } }}Which statement is true?A. There is a syntax error on line 1.B. There are syntax errors on lines 1 and 6.C. There are syntax errors on lines 1, 6, and 8.D. There is a syntax error on line 6.Answer & ExplanationAnswer: Option D

Explanation:

Page 25: First Assessment Test Questions With Answers

Using the integer 1 in the while statement, or any other looping or conditional construct for that matter, will result in a compiler error. This is old C Program syntax, not valid Java.A, B and C are incorrect because line 1 is valid (Java is case sensitive so While is a valid class name). Line 8 is also valid because an equation may be placed in a String operation as shown.

16.void start() { A a = new A(); B b = new B(); a.s(b); b = null; /* Line 5 */ a = null; /* Line 6 */ System.out.println("start completed"); /* Line 7 */} When is the B object, created in line 3, eligible for garbage collection?A. after line 5B. after line 6C. after line 7D. There is no way to be absolutely certain.Answer & ExplanationAnswer: Option D

17.class Bar { } class Test { Bar doBar() { Bar b = new Bar(); /* Line 6 */ return b; /* Line 7 */ } public static void main (String args[]) { Test t = new Test(); /* Line 11 */ Bar newBar = t.doBar(); /* Line 12 */ System.out.println("newBar"); newBar = new Bar(); /* Line 14 */ System.out.println("finishing"); /* Line 15 */ } }At what point is the Bar object, created on line 6, eligible for garbage collection?A. after line 12B. after line 14C. after line 7, when doBar() completesD. after line 15, when main() completesAnswer & ExplanationAnswer: Option B

Explanation:Option B is correct. All references to the Bar object created on line 6 are destroyed when a new reference to a new Bar object is assigned to the variable newBar on line 14. Therefore the Bar object, created on line 6, is eligible for garbage collection after line 14.Option A is wrong. This actually protects the object from garbage collection.

Page 26: First Assessment Test Questions With Answers

Option C is wrong. Because the reference in the doBar() method is returned on line 7 and is stored in newBar on line 12. This preserver the object created on line 6.Option D is wrong. Not applicable because the object is eligible for garbage collection after line 14.

18.What will be the output of the program?

public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( "Finally" ); } } }A. FinallyB. Compilation fails.C. The code runs with no output.D. An exception is thrown at runtime.Answer & ExplanationAnswer: Option A

Explanation:If you put a finally block after a try and its associated catch blocks, then once execution enters the try block, the code in that finally block will definitely be executed except in the following circumstances:An exception arising in the finally block itself.The death of the thread.The use of System.exit()Turning off the power to the CPU.I suppose the last three could be classified as VM shutdown.

19.What will be the output of the program?

public class X { public static void main(String [] args) { try { badMethod(); //Exception Will Be thrown System.out.print("A"); } catch (RuntimeException ex) /* Line 10 */ { System.out.print("B"); } catch (Exception ex1) {

Page 27: First Assessment Test Questions With Answers

System.out.print("C"); } finally { System.out.print("D"); } System.out.print("E"); } public static void badMethod() { throw new RuntimeException(); } }A. BDB. BCDC. BDED. BCDEAnswer & ExplanationAnswer: Option C

Explanation:A Run time exception is thrown and caught in the catch statement on line 10. All the code after the finally statement is run because the exception has been caught.

20.public class X { public static void main(String [] args) { X x = new X(); X x2 = m1(x); /* Line 6 */ X x4 = new X(); x2 = x4; /* Line 8 */ doComplexStuff(); } static X m1(X mx) { mx = new X(); return mx; }}After line 8 runs. how many objects are eligible for garbage collection?A. 0 B. 1C. 2D. 3Answer & ExplanationAnswer: Option B