OOC Using Java- Post Test

Embed Size (px)

DESCRIPTION

java infysys pre test

Citation preview

Object Oriented Concepts Using Java > Post Test1. What is the output of following code snippet?

interface InterOne{

int varOne=1000;

int varTwo=2000;

void display();

}

abstract class AbstractOne{

int varThree;

abstract void disp();

}

class Example extends AbstractOne implements InterOne{

int varThree;

Example(){

varThree=10;

}}

public void display(){

System.out.println("varOne value:"+varOne);

}

public void disp(){

int varThree=100;

System.out.println("varTwo value :"+varTwo);

System.out.println("varThree value:"+varThree);

System.out.println("varThree value:"+super.varThree);

}

}class Demo{

public static void main(String args[]){

Example obj=new Example();

obj.display();

obj.disp();

}

}Options a)varOne value:1000 varTwo value:2000 varThree value:100 varThree value:0b)varOne value:1000 varTwo value:2000 varThree value:10 varThree value:0c) varOne value:1000 varTwo value:2000 varThree value:100 varThree value:10d) varOne value:1000 varTwo value:2000 varThree value:0 varThree value:100

Answer:a2 Consider the following:

There is a class called Shape in a package called draw.

Choose the option which represents the CORRECT statement which will import the Shape class from the draw package into another packageOptionsa)impot draw*;

b)import draw.*;c)import Shape.draw.*;d)import java.draw.*;

answer:b

3 What is the output of following code snippet?

abstract class ExampleOne{

int dataOne=1000;

abstract void display();

}

class ExampleTwo extends ExampleOne{

int dataTwo;

ExampleTwo(int varOne){

dataTwo=varOne;

}

public void disp(){

System.out.println("Infosys Bangalore");

} public void display(){

System.out.println(dataOne);

}

}

class Example{

public static void main(String args[]){

ExampleOne obj=new ExampleTwo(20);

obj.disp();

obj.display();

}

}Optionsa)Compilation error :cannot find symbol disp()

b)Infosys Bangalore 0 c)Infosys Bangalore

d) Infosys Bangalore 1000

answer: a

4 Which of the following statement is TRUE related to Interfaces?Options

answer: ca)An object of an interface can be instantiated

b)All the methods in an interface are final by defaultc)All the methods in an interface are abstract by defaultd)Interfaces contain only methods and cannot contain variables

5 Consider that a main method is declared as public static void main(String []args). Choose the option that represents the expression to find the number of command line arguments passed to the main method.Optionsa) args.length 1

b) args.lengthc) args.length () 1

d) args.length ()

answer: b

6 What is the output of following code snippet?

class Demo{

public static void main(String args[]){

String string1 = new String("ABC");

String string2= new String("ABC");

System.out.println(string1==string2);

System.out.println(string1.equals(string2));

}

}Optionsa) true true

b) true falsec) false false

d) false true

answer: d

7 What is the output of following code snippet?

public class MainDemo{

public static void main(String args[]){

float arrayOne[] = {1, 2, 3, 4,5};

for(int iIndex=0; iIndexAccount number should be generated by system in the ascending order

->The system should record the name and address of the account holder as these are mandatory

->The minimum amount to open an account is $100

->Each account holder gets a user name and password that he can use to login on web interface for basic services

2. OPERATING ON DEPOSITORY ACCOUNT

a. Deposit Cash

->A deposit should be for a minimum amount of $10

->Deposit should be a multiple of $10

->Whenever a deposit is made, the updated balance should be made known to the account holder

->There is no upper limit for account balance in case of current and fixed deposit account types

->Savings bank account have an upper limit of $500,000 as account balance

->For fixed depository account, only one time deposit is allowed

b. Withdraw Cash

For Current and Saving account type

->Cash can be withdrawn by Cheques and Debit Cards

->Minimum amount of withdrawal is $10

->Account balance should never be less than $100 for saving account and $0 for current account(No overdraft facility is available)

->Whenever a withdrawal is made, the updated balance should be made known to the account holder

->Withdrawals may be made from any of the branches or through ATM outlets as designated by the bank

->With the bank's debit card, one can shop using on-line debit module and charge to the account directly

For Fixed deposit account type

->Withdrawal from an account will result in the closing of the account

->On closing of fixed deposit account type principle amount along with applicable interest should be made available to the customer

c. Fund Transfer

->Only intra bank fund transfer is allowed

->Each user has a maximum fund transfer limit of $1000 per day

->Fund transfer will adhere to standard deposit and withdrawal rules

d. Related Services

->Demand draft request

->Password change request

->Account statement request

->Request for cheque books

3. OPERATING ON LOAN ACCOUNT

Different loan schemes provided by Global Corp bank are listed as follows:

i. Education Loan

ii. Vehicle Loan

iii. House Building Loan

iv. Business Loan

v. Agriculture Loan

vi. Consumer Electronics Loan

->Minimum amount, maximum amount, term of loan, rate of interest and requirement of mortgage depends upon the repayment capability of the applicant

->Bank will provide loans to its account holders charging a higher rate of interest than that given by the bank to saving and current account customers4. CLOSING AN ACCOUNT

->Before closing an account, the account balance should be zero

->The status of the account will be set to "closed"

->All accounts that have not been operated for 10 years will be considered as dormant account

------------------------------------------------------------------------------

Question:The criteria to be met for closing an account by a customer is that the account balance should be zero. For using this functionality , the user has to choose an option 4 from a menu.When the account is closed, the status of the Account is set to 'Closed' for the customer. Which of these options demonstrate this functionality?

Assumptions:

UserChoice is a variable that contains the choice entered by the user to execute functionality. The option number 4 is used to close an account

UserAccountBal: The variable which contains the balance in the account of the current user account

setStatus() method is used to set the status of the account i.e. 'Open' or 'Closed'.(i) If(UserChoice==4){

If (UserAccountBal==0){

account.setStatus("Closed");

}

}

(ii) If(UserChoice==4 || UserAccountBal==0){

account.setStatus("Closed");

}Optionsa)Only (i)

b) Only (ii)c) Neither (i) nor (ii)

d)both (i) & (ii)

answer:a

9 Case Study

------------------------------------------------------------------------------

Global Corp Bank is a global banking organization that provides standard banking services to its customers spread across the globe. The vision of the bank is 'Banking Simplified'. The head office is located in Chicago and the bank has presence in more than 30 countries with client base of nearly 600,000. The bank has several branches in different cities; each branch is identified by a 4 digit code.

Global Corp Bank is well known among its clients for world-class processes, speed of execution and financial acumen. The bank has made a proposal for investing around $200 million in setting-up 24x7 banking support facilities for the customers. The aim of the proposed banking system is to create a paperless bank. The bank leverages IT for automating several of its business processes which includes:

Managing Customer Accounts

Transaction Management

The account holders are provided with a web-based interface for the following basic services:

Checking Account Balance

Fund transfer

Changing the account password

Request for demand draft and/or Cheque Books

Problem Statement:

Over the last couple of years the reach of Global Corp has grown significantly. It has seen a radical rise in the number of clients and transactions. Recently the bank has also witnessed a dramatic increase in competition from other financial institutions. This market situation has prompted Global Corp to introduce new efficient, reliable and scalable operational methodologies.

Functional Specifications:

Global Corp bank provides following account services:Options1. Depository Accounts

a. Current account

b. Fixed deposit account

c. Savings bank account

2. Loan Accounts

a. Education Loan

b. Vehicle Loan

c. House Building Loan

d. Business Loan

e. Agriculture Loan

f. Consumer Electronics Loan

Related functionalities for the account services: 1. Opening an account

2. Operating on depository account

a. Deposit cash

b. Withdraw cash

c. Fund Transfer

d. Related Services

3. Operating on loans account

4. Closing an account

1. OPENING AN ACCOUNT

Each new opened account should have a 13 character unique account number. The account number should be in the following format: CCXXXYYYYZZZZ

Here,

CC denotes the account type. For example:

DC : Depository Current Account

LH : Loan Account for Home

XXX denotes bank code which is 717 for the Global Corp bank

YYYY denotes branch code which varies from branch to branch

ZZZZ denotes the customer number which starts from 0001 for a account type in a branch and increments sequentially by 1

->It should not be possible to modify the account number at any stage >Account number should be generated by system in the ascending order

->The system should record the name and address of the account holder as these are mandatory

->The minimum amount to open an account is $100

->Each account holder gets a user name and password that he can use to login on web interface for basic serviceshe can use to login on web interface for basic services

2. OPERATING ON DEPOSITORY ACCOUNT

a. Deposit Cash

->A deposit should be for a minimum amount of $10

->Deposit should be a multiple of $10

->Whenever a deposit is made, the updated balance should be made known to the account holder

->There is no upper limit for account balance in case of current and fixed deposit account types

->Savings bank account have an upper limit of $500,000 as account balance

->For fixed depository account, only one time deposit is allowedb. Withdraw Cash

For Current and Saving account type

->Cash can be withdrawn by Cheques and Debit Cards

->Minimum amount of withdrawal is $10

->Account balance should never be less than $100 for saving account and $0 for current account(No overdraft facility is available)

->Whenever a withdrawal is made, the updated balance should be made known to the account holder

->Withdrawals may be made from any of the branches or through ATM outlets as designated by the bank

->With the bank's debit card, one can shop using on-line debit module and charge to the account directly

For Fixed deposit account type

->Withdrawal from an account will result in the closing of the account

->On closing of fixed deposit account type principle amount along with applicable interest should be made available to the customer

c. Fund Transfer

->Only intra bank fund transfer is allowed

->Each user has a maximum fund transfer limit of $1000 per day

->Fund transfer will adhere to standard deposit and withdrawal rules

d. Related Services

->Demand draft request

->Password change request

->Account statement request

->Request for cheque books

3. OPERATING ON LOAN ACCOUNT

Different loan schemes provided by Global Corp bank are listed as follows:

i. Education Loan

ii. Vehicle Loan

iii. House Building Loan

iv. Business Loan

v. Agriculture Loan

vi. Consumer Electronics Loan

->Minimum amount, maximum amount, term of loan, rate of interest and requirement of mortgage depends upon the repayment capability of the applicant

->Bank will provide loans to its account holders charging a higher rate of interest than that given by the bank to saving and current account customers4. CLOSING AN ACCOUNT

->Before closing an account, the account balance should be zero

->The status of the account will be set to "closed"

->All accounts that have not been operated for 10 years will be considered as dormant account

------------------------------------------------------------------------------

The account number of an Account is auto generated every time a new account is created.This holds whole numbers. The accountNumber variable contains the unique account number for every Account. What should be the datatype of the Account number variable ?

a) char

b) intc) static int

d) static char

answer: b

10 Case Study

------------------------------------------------------------------------------

Global Corp Bank is a global banking organization that provides standard banking services to its customers spread across the globe. The vision of the bank is 'Banking Simplified'. The head office is located in Chicago and the bank has presence in more than 30 countries with client base of nearly 600,000. The bank has several branches in different cities; each branch is identified by a 4 digit code.

Global Corp Bank is well known among its clients for world-class processes, speed of execution and financial acumen. The bank has made a proposal for investing around $200 million in setting-up 24x7 banking support facilities for the customers. The aim of the proposed banking system is to create a paperless bank. The bank leverages IT for automating several of its business processes which includes:

Managing Customer Accounts

Transaction Management

The account holders are provided with a web-based interface for the following basic services:

Checking Account Balance

Fund transfer

Changing the account password

Request for demand draft and/or Cheque Books

Problem Statement:

Over the last couple of years the reach of Global Corp has grown significantly. It has seen a radical rise in the number of clients and transactions. Recently the bank has also witnessed a dramatic increase in competition from other financial institutions. This market situation has prompted Global Corp to introduce new efficient, reliable and scalable operational methodologies.

Functional Specifications:

Global Corp bank provides following account services:

1. Depository Accounts

a. Current account

b. Fixed deposit account

c. Savings bank account

2. Loan Accounts

a. Education Loan

b. Vehicle Loan

c. House Building Loan

d. Business Loan

e. Agriculture Loan

f. Consumer Electronics Loan

Related functionalities for the account services:

1. Opening an account

2. Operating on depository account

a. Deposit cash

b. Withdraw cash

c. Fund Transfer

d. Related Services

3. Operating on loans account

4. Closing an account

1. OPENING AN ACCOUNT

Each new opened account should have a 13 character unique account number. The account number should be in the following format:

CCXXXYYYYZZZZ

Here,

CC denotes the account type. For example:

DC : Depository Current Account

LH : Loan Account for Home

XXX denotes bank code which is 717 for the Global Corp bank

YYYY denotes branch code which varies from branch to branch

ZZZZ denotes the customer number which starts from 0001 for a account type in a branch and increments sequentially by 1

->It should not be possible to modify the account number at any stage

->Account number should be generated by system in the ascending order

->The system should record the name and address of the account holder as these are mandatory

->The minimum amount to open an account is $100

->Each account holder gets a user name and password that he can use to login on web interface for basic services

2. OPERATING ON DEPOSITORY ACCOUNT

a. Deposit Cash

->A deposit should be for a minimum amount of $10

->Deposit should be a multiple of $10

->Whenever a deposit is made, the updated balance should be made known to the account holder

->There is no upper limit for account balance in case of current and fixed deposit account types

->Savings bank account have an upper limit of $500,000 as account balance

->For fixed depository account, only one time deposit is allowed

b. Withdraw Cash

For Current and Saving account type

->Cash can be withdrawn by Cheques and Debit Cards

->Minimum amount of withdrawal is $10

->Account balance should never be less than $100 for saving account and $0 for current account(No overdraft facility is available)

->Whenever a withdrawal is made, the updated balance should be made known to the account holder

->Withdrawals may be made from any of the branches or through ATM outlets as designated by the bank

->With the bank's debit card, one can shop using on-line debit module and charge to the account directly

For Fixed deposit account type

->Withdrawal from an account will result in the closing of the account

->On closing of fixed deposit account type principle amount along with applicable interest should be made available to the customer

c. Fund Transfer

->Only intra bank fund transfer is allowed

->Each user has a maximum fund transfer limit of $1000 per day

->Fund transfer will adhere to standard deposit and withdrawal rules

d. Related Services

->Demand draft request

->Password change request

->Account statement request

->Request for cheque books

3. OPERATING ON LOAN ACCOUNT

Different loan schemes provided by Global Corp bank are listed as follows:

i. Education Loan

ii. Vehicle Loan

iii. House Building Loan

iv. Business Loan

v. Agriculture Loan

vi. Consumer Electronics Loan

->Minimum amount, maximum amount, term of loan, rate of interest and requirement of mortgage depends upon the repayment capability of the applicant

->Bank will provide loans to its account holders charging a higher rate of interest than that given by the bank to saving and current account customers

4. CLOSING AN ACCOUNT

->Before closing an account, the account balance should be zero

->The status of the account will be set to "closed"

->All accounts that have not been operated for 10 years will be considered as dormant account

------------------------------------------------------------------------------

A developer is working on the menu navigation of the application. The menu requires taking user input through command line arguments. The choices available to user in the menu are numeric in nature. But, when the number value (e.g. 4) is passed through command line arguments and used in the program ,there is an error message:

Type mismatch: cannot convert from String to int

What could be the possible solution to this issue?Optionsa) Accept the argument in a string formatb) Convert the argument into an integer type using Integer.decode()methodc) Convert the argument into an integer type using Integer.parselnt() methodd) Convert the argument into an integer type using Integer.toString()metod

answer:c

11 Case Study

------------------------------------------------------------------------------

Global Corp Bank is a global banking organization that provides standard banking services to its customers spread across the globe. The vision of the bank is 'Banking Simplified'. The head office is located in Chicago and the bank has presence in more than 30 countries with client base of nearly 600,000. The bank has several branches in different cities; each branch is identified by a 4 digit code.

Global Corp Bank is well known among its clients for world-class processes, speed of execution and financial acumen. The bank has made a proposal for investing around $200 million in setting-up 24x7 banking support facilities for the customers. The aim of the proposed banking system is to create a paperless bank. The bank leverages IT for automating several of its business processes which includes:

Managing Customer Accounts

Transaction Management

The account holders are provided with a web-based interface for the following basic services:

Checking Account Balance

Fund transfer

Changing the account password

Request for demand draft and/or Cheque Books

Problem Statement:

Over the last couple of years the reach of Global Corp has grown significantly. It has seen a radical rise in the number of clients and transactions. Recently the bank has also witnessed a dramatic increase in competition from other financial institutions. This market situation has prompted Global Corp to introduce new efficient, reliable and scalable operational methodologies.

Functional Specifications:

Global Corp bank provides following account services:

1. Depository Accounts

a. Current account

b. Fixed deposit account

c. Savings bank account

2. Loan Accounts

a. Education Loan

b. Vehicle Loan

c. House Building Loan

d. Business Loan

e. Agriculture Loan

f. Consumer Electronics Loan

Related functionalities for the account services:

1. Opening an account

2. Operating on depository account

a. Deposit cash

b. Withdraw cash

c. Fund Transfer

d. Related Services

3. Operating on loans account

4. Closing an account

1. OPENING AN ACCOUNT

Each new opened account should have a 13 character unique account number. The account number should be in the following format:

CCXXXYYYYZZZZ

Here,

CC denotes the account type. For example:

DC : Depository Current Account

LH : Loan Account for Home

XXX denotes bank code which is 717 for the Global Corp bank

YYYY denotes branch code which varies from branch to branch

ZZZZ denotes the customer number which starts from 0001 for a account type in a branch and increments sequentially by 1

->It should not be possible to modify the account number at any stage

->Account number should be generated by system in the ascending order

->The system should record the name and address of the account holder as these are mandatory

->The minimum amount to open an account is $100

->Each account holder gets a user name and password that he can use to login on web interface for basic services

2. OPERATING ON DEPOSITORY ACCOUNT

a. Deposit Cash

->A deposit should be for a minimum amount of $10

->Deposit should be a multiple of $10

->Whenever a deposit is made, the updated balance should be made known to the account holder

->There is no upper limit for account balance in case of current and fixed deposit account types

->Savings bank account have an upper limit of $500,000 as account balance

->For fixed depository account, only one time deposit is allowed

b. Withdraw Cash

For Current and Saving account type

->Cash can be withdrawn by Cheques and Debit Cards

->Minimum amount of withdrawal is $10

->Account balance should never be less than $100 for saving account and $0 for current account(No overdraft facility is available)

->Whenever a withdrawal is made, the updated balance should be made known to the account holder

->Withdrawals may be made from any of the branches or through ATM outlets as designated by the bank

->With the bank's debit card, one can shop using on-line debit module and charge to the account directly

For Fixed deposit account type

->Withdrawal from an account will result in the closing of the account

->On closing of fixed deposit account type principle amount along with applicable interest should be made available to the customer

c. Fund Transfer

->Only intra bank fund transfer is allowed

->Each user has a maximum fund transfer limit of $1000 per day

->Fund transfer will adhere to standard deposit and withdrawal rules

d. Related Services

->Demand draft request

->Password change request

->Account statement request

->Request for cheque books

3. OPERATING ON LOAN ACCOUNT

Different loan schemes provided by Global Corp bank are listed as follows:

i. Education Loan

ii. Vehicle Loan

iii. House Building Loan

iv. Business Loan

v. Agriculture Loan

vi. Consumer Electronics Loan

->Minimum amount, maximum amount, term of loan, rate of interest and requirement of mortgage depends upon the repayment capability of the applicant

->Bank will provide loans to its account holders charging a higher rate of interest than that given by the bank to saving and current account customers

4. CLOSING AN ACCOUNT

->Before closing an account, the account balance should be zero

->The status of the account will be set to "closed"

->All accounts that have not been operated for 10 years will be considered as dormant account

------------------------------------------------------------------------------

The design document mentions that the Account class contains the template for creating an account and the specific features are implemented in the various types of account classes. A software engineer tries to create an object of the Account class within one of the methods of the Customer class but is unable to do so and gets an error. What could be the most probable reason for this?Optionsa) The Account class is declared as a private class

b) The Account class cannot be inherited the object be madec) An object of Account class cannot be made in another class except the class that contains maind) Account class is designed to be an abstract class

answer: d

12 Case Study

------------------------------------------------------------------------------

Global Corp Bank is a global banking organization that provides standard banking services to its customers spread across the globe. The vision of the bank is 'Banking Simplified'. The head office is located in Chicago and the bank has presence in more than 30 countries with client base of nearly 600,000. The bank has several branches in different cities; each branch is identified by a 4 digit code.

Global Corp Bank is well known among its clients for world-class processes, speed of execution and financial acumen. The bank has made a proposal for investing around $200 million in setting-up 24x7 banking support facilities for the customers. The aim of the proposed banking system is to create a paperless bank. The bank leverages IT for automating several of its business processes which includes:

Managing Customer Accounts

Transaction Management

The account holders are provided with a web-based interface for the following basic services:

Checking Account Balance

Fund transfer

Changing the account password

Request for demand draft and/or Cheque Books

Problem Statement:

Over the last couple of years the reach of Global Corp has grown significantly. It has seen a radical rise in the number of clients and transactions. Recently the bank has also witnessed a dramatic increase in competition from other financial institutions. This market situation has prompted Global Corp to introduce new efficient, reliable and scalable operational methodologies.

Functional Specifications:

Global Corp bank provides following account services:

1. Depository Accounts

a. Current account

b. Fixed deposit account

c. Savings bank account

2. Loan Accounts

a. Education Loan

b. Vehicle Loan

c. House Building Loan

d. Business Loan

e. Agriculture Loan

f. Consumer Electronics Loan

Related functionalities for the account services:

1. Opening an account

2. Operating on depository account

a. Deposit cash

b. Withdraw cash

c. Fund Transfer

d. Related Services

3. Operating on loans account

4. Closing an account

1. OPENING AN ACCOUNT

Each new opened account should have a 13 character unique account number. The account number should be in the following format:

CCXXXYYYYZZZZ

Here,

CC denotes the account type. For example:

DC : Depository Current Account

LH : Loan Account for Home

XXX denotes bank code which is 717 for the Global Corp bank

YYYY denotes branch code which varies from branch to branch

ZZZZ denotes the customer number which starts from 0001 for a account type in a branch and increments sequentially by 1

->It should not be possible to modify the account number at any stage

->Account number should be generated by system in the ascending order

->The system should record the name and address of the account holder as these are mandatory

->The minimum amount to open an account is $100

->Each account holder gets a user name and password that he can use to login on web interface for basic services

2. OPERATING ON DEPOSITORY ACCOUNT

a. Deposit Cash

->A deposit should be for a minimum amount of $10

->Deposit should be a multiple of $10

->Whenever a deposit is made, the updated balance should be made known to the account holder

->There is no upper limit for account balance in case of current and fixed deposit account types

->Savings bank account have an upper limit of $500,000 as account balance

->For fixed depository account, only one time deposit is allowed

b. Withdraw Cash

For Current and Saving account type

->Cash can be withdrawn by Cheques and Debit Cards

->Minimum amount of withdrawal is $10

->Account balance should never be less than $100 for saving account and $0 for current account(No overdraft facility is available)

->Whenever a withdrawal is made, the updated balance should be made known to the account holder

->Withdrawals may be made from any of the branches or through ATM outlets as designated by the bank

->With the bank's debit card, one can shop using on-line debit module and charge to the account directly

For Fixed deposit account type

->Withdrawal from an account will result in the closing of the account

->On closing of fixed deposit account type principle amount along with applicable interest should be made available to the customer

c. Fund Transfer

->Only intra bank fund transfer is allowed

->Each user has a maximum fund transfer limit of $1000 per day

->Fund transfer will adhere to standard deposit and withdrawal rules

d. Related Services

->Demand draft request

->Password change request

->Account statement request

->Request for cheque books

3. OPERATING ON LOAN ACCOUNT

Different loan schemes provided by Global Corp bank are listed as follows:

i. Education Loan

ii. Vehicle Loan

iii. House Building Loan

iv. Business Loan

v. Agriculture Loan

vi. Consumer Electronics Loan

->Minimum amount, maximum amount, term of loan, rate of interest and requirement of mortgage depends upon the repayment capability of the applicant

->Bank will provide loans to its account holders charging a higher rate of interest than that given by the bank to saving and current account customers

4. CLOSING AN ACCOUNT

->Before closing an account, the account balance should be zero

->The status of the account will be set to "closed"

->All accounts that have not been operated for 10 years will be considered as dormant account

------------------------------------------------------------------------------

The Account class contains the Account number. The Account number is generated by a function generateAccountNumber() in the Account class. This variable should be modified by classes within the package of the Account class and by the child classes of Account classes in a different package. What would be the most appropriate access specifier for this variable?Optionsa)default

b) privatec) protected

answer:c

13 Which of the following is/are TRUE with respect to static keyword?

(i)static variables can be accessed by non-static methods in the class

(ii)static variables can be accessed only by static methods in the class

(iii)static members can be accessed with object or class reference

(iv)static members are accessed only with class referenceOptionsa) Options (ii) and (iv) onlyb) Options (i) and (iv) onlyc) Options (i) and (iii) onlyd) Only (i)

answer:c

14 . What is the output of the following code snippet?

public class Customers {

static int count;

String name;

Customers(String name){

count++;

this.name=name;

System.out.println("The number of Customers:"+count);

}

public static void main(String[] args) {

Customers customer1=new Customers("Shekar");

Customers customer2=new Customers("Amit");

}

}Optionsa) The number of Customers: 1 The number of Customers: 1b) The number of Customers: 0 The number of Customers: 1c) The number of Customers: 1 The number of Customers: 2

answer: c

15 . What is the output of the following code snippet?

class Student {

double marks;

Student(){

System.out.println("In Default Constructor");

this.marks=58.0;

System.out.println(this.marks);

}

Student(String type){

System.out.println("In "+type+ " Constructor");

this.marks=100.0;

System.out.println(this.marks);

}

Student(double marks){

System.out.println("In Double Constructor");

this.marks=69.0;

System.out.println(this.marks);

}

public static void main(String[] args) {

Student students1=new Student("Double");

}

}Optionsa) In Default Constructor 58.0b) In Double Constructor 100.0c) In Double Constructor 69.0

answer:b

16 . What is the output of the following code snippet?

public class College{

int year;

String name;

College(int year,String name){

year=year;

name=name;

}

public static void main(String[] args) {

College first=new College(1998,"BITS");

System.out.println("The year is:"+first.year);

System.out.println("The name is:"+first.name);

}

}Optionsa) The year is: null The year is: null

b) The year is: 1998 The year is: BITSc) The year is: 0 The year is: BITS

d) The year is: 0 The year is: null

answer:d

17 . Which of the following is TRUE with respect to reference variables?

(i)Printing a reference will NOT print the address of the object

referred by it

(ii)Printing a reference will print the address of the object

referred by it

(iii)& operator CANNOT be used on reference variables to print

their address

(iv)& operator can be used on reference variables to print their

addressOptions

answer:2a) Options (i) & (iv) onlyb) Options (i) & (iii) onlyc) Options (ii) & (iii) onlyd) Options (ii) & (iv) only

18 . What is the output of following code snippet?

class One

{

One()

{

System.out.println("One");

}

}

class Two extends One

{

Two(String msg)

{

System.out.println(msg);

}

}

class Three extends Two

{

String msg = "Three";

Three(String msg)

{

super(msg);

System.out.println(this.msg);

}

}

class Demo

{

public static void main(String args[])

{

Three obj = new Three("Two");

}

}Optionsa) Two Three

b) One Three Twoc) Three Two

d) One Two Three

answer: d

19 . Consider the following scenario:

A package pack1 is created alongwith a class Base inside the package

A package pack2 is created with a class Derived . This class extends the class Base in pack1 package

Choose from among the access specifier of variables in class Base which would NOT be accessible in the class Derived.Optionsa) public specifier

b) default specifierc) protected specifier

answer: b

20 . Consider the following scenario:

A package pack1 is created alongwith a class Base inside the package

A package pack2 is created with a class Derived . This class extends the class Base in pack1 package

Choose from among the access specifier of variables in class Base which would NOT be accessible in the class Derived.Optionsa) int baseMtd(int iNum, char cVal) { return 0; }b) void baseMtd(char cVal, int iNum) { }c) void overload BaseMtd(int iNum, char cVal) { }

d) void baseMtd(int ild, char cStatus) { }

answer:b

21 . The following code is giving compilation errors.

1 public class Question {

2 public static void main(String[] args) {

3 float floatVar,anotherFloatVar=3;

4 int result,intVar=3;

5 floatVar= (float)intVar+anotherFloatVar;

6 result=intVar*anotherFloatVar;

7 System.out.println("The result is "+result);

8 }

9 }

Choose the line which gives the error and a suitable replacement so that the output of the program is The result is 9Options

answer: ba) Replace line 6 with: (float)result=intVar*anotherFloatVar;

b) Replace line 6 with: result= intVar*(int)anotherFloatVar; c) Replace line 6 with: result= (int)intVar*anotherFloatVar;

d) Replace line 5 with: floatVar= (int)(intVar+anotherFloatVar);

22 . What is the output of the following code snippet?

public class Question {

public static void main(String[] args) {

int counter = 50;

boolean val= true;

while (val)

{

if (counter < 20 && counter>10)

{

continue;

}

if (counter < 30)

{

break;

}

counter = counter - 10;

}

System.out.println("Value is: " + counter);

}

}Options

answer: da) Compilation error: Incorrect if statementb) No output because it goes into an infinite loopc) Compilation error: Exxpected else `if d) Value is: 20

23 . What is the output of the following code snippet?

public class Question {

public static void main(String[] args) {

int var = 22, anotherVar = 7, result;

String str = "One";

String anotherStr = "Two";

result = var*anotherVar/anotherVar;

if ( result < 22)

{

System.out.println(str);

result = result+1;

}

else

{

System.out.println(anotherStr);

result = var + anotherVar;

}

}

}Optionsa) one

b) Twoc) None of the given options

d) Compilationerror: incorrect use of operators answer: b

24 . Which of the following is a VALID variable declaration as per java coding standards that you have studied for storing an employee name?Optionsa) EMPname

b)EMPNAMEc) EmpName

d) empName

answer: d

25 . Which of the following is NOT a primitive data type?Optionsa) String

b)intc) double

d) byte

answer: a