MCQ on Java Programming With Answers set-11


1. If m and n are int type variables, what will be the result of the expression m%n when m=-14 and n=-3?

A) 4

B) 2

C) -2

D) -4



2. Consider the following code

if(number>=0)

    if(number>0)

    system.out.println("Number is positive");

else

    system.out.println("Number is negative");

What will be the output if number is equal to 0?

A) Number is negative

B) Number is positive

C) Both A and B

D) None of the above



3. Consider the following code:

char c='a';

switch (c)

{
     case 'a';

     system.out.println("A");

     case 'b'; 

     system.out.println("B");

     default; 


system.out.println("C");
} 

For this code, which of the following statement is true?

A) Output will be A

B) Output will be A followed by B

C) Output will be A, followed by B, and then followed by C

D) Code is illegal and therefore will not compile



4. Consider the following class definition.

class Student extends String

  {
  }

What happens when we try to compile this class?


A) Will not compile because class body is not defined

B) Will not compile because the class in not declared public.

C) Will not compile because string is abstract.

D) Will not compile because string is final.



5. What is wrong in the following class definitions?

abstract class print

{
  abstract show();
}
class Display extends Print
{
}

A) Nothing is wrong

B) Wrong. Method show() should have a return type

C) Wrong. Method show() is not implemented in Display

D) Wrong. Display does not contain any numbers.



6. What is the error in the following class definitions?

abstract class XY
{
  abstract sum(int x, int y){    }
}

A) Class header is not defined properly

B) Constructor is not defined

C) Method is not defined properly

D) No error.




7. Which of the following statements are true?

i) We cannot use abstract classes to instantiate objects directly.

ii) The abstract methods of an abstract class must be defined in its subclass.

iii) We cannot declare abstract constructors.

iv) We may declare abstract static methods.

A) Line i only

B) Line ii only

C) Line i and ii only

D) Line i, ii and iii only




8. We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would archive this?

A) Private

B) Protected

C) Public

D) Private Protected




9. The use of protected keyword to a member in a class will restrict its visibility as follows:

A) Visible only in the class and its subclass in the same package.

B) Visible only inside the same package.

C) Visible in all classes in the same package and subclasses in other packages

D) Visible only in the class where it is declared.




10. Consider the following code:

interface Area
{
  float compute (float x, float y);
}
class Room implements Area
{
  float compute (float x, float y)

      {
  return(x&y);
 }
 }

What is wrong with the code?

A) Interface definition is incomplete

B) Method compute() in interface Area should be declared public

C) Method compute() in class Room should be declared public

D) All the above





Answers:



1. If m and n are int type variables, what will be the result of the expression m%n when m=-14 and n=-3?

C) -2


2. Consider the following code

if(number>=0)
    if(number>0)
    system.out.println("Number is positive");
else
    system.out.println("Number is negative");

What will be the output if number is equal to 0?

A) Number is negative


3. Consider the following code:

char c='a';
switch (c)
{
     case 'a';
     system.out.println("A");
     case 'b'; 
     system.out.println("B");
     default; 
     system.out.println("C");
} 

For this code, which of the following statement is true?

B) Output will be A followed by B


4. Consider the following class definition.

  class Student extends String
  {
  }

What happens when we try to compile this class?

D) Will not compile because string is final.


5. What is wrong in the following class definitions?

abstract class print
{
    abstract show();
}
class Display extends Print
{
}

C) Wrong. Method show() is not implemented in Display


6. What is the error in the following class definitions?

abstract class XY
{
   abstract sum(int x, int y){    }
}


C) Method is not defined properly


7. Which of the following statements are true?

i) We cannot use abstract classes to instantiate objects directly.

ii) The abstract methods of an abstract class must be defined in its subclass.

iii) We cannot declare abstract constructors.

iv) We may declare abstract static methods.

D) Line i, ii and iii only


8. We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would archive this?

D) Private Protected


9. The use of protected keyword to a member in a class will restrict its visibility as follows:

C) Visible in all classes in the same package and subclasses in other packages


10. Consider the following code:

interface Area
{
     float compute (float x, float y);
}
class Room implements Area
{
    float compute (float x, float y)
      {
           return(x&y);
      }
 }

What is wrong with the code?

C) Method compute() in class Room should be declared public




Related Posts



For other more Multiple Choice Questions (MCQs): Click Here

continue reading

Write a Program in C to Find if a Number is Present in a List or not


C Program to Find if a Number is Present in a List
Here is a C program to find if a number is present in a list of N numbers or not.


In this program for loop is used to search a number from the list of numbers and array of numbers is used to insert numbers in a list.


If the searched number is matched with any number in the list it throws to print it is presented in the list and if the searched number is not matched with any number in the list it throws to print it is not presented in the list.







 A C Program to Find if a Number is Present in a List of N numbers or not





Steps:
  1.  At first declare integers i, n, m, and array of integers a[10].
  2. Print the message to enter how many elements want to insert and allow to insert.
  3. Print the message to enter the elements in the array.
  4. Use for loop to find out whether the given number is present in the list or not.
  5. Print the message on the screen whether the given number is present in the list or not.




Code:



#include<stdio.h>
#include<conio.h>

void main()
{
	int i,n,m,flag=0; int a[10];
	clrscr();

	printf("How many elements you want to enter \n");
	scanf("%d",&n);

	printf("Enter element in the array \n");
	for (i=0; i<n; i++)
	scanf("%d", &a[i]);

	printf("Enter the element you want to search \n");
	scanf("%d", &m);

	for (i=0; i<n; i++)
		{
			if(a[i]==m)
			{
			flag=1;
			break;
			}
		}
	if(flag==0)
		printf("Not present");
	else
		printf("Present");
	getch();
}




Related Posts:



continue reading

C Program to Find the Sum and Average of Numbers Using Do-While Loop


C Program to Find the Sum and Average of Numbers Using Do-While Loop
In this program sum and average of of the given numbers are calculated using do-while loop.

Do-while loop is a looping condition where statements are executed continuously until the condition validates and test the condition after having executed the statements within the loop.

This means that do-while would execute its statements at least once, even if the condition fails for the first time.
 
Scanf() command is used here to allow enter the numbers and sum=sum+num; to sum the numbers within do-while loop.



C Program to Find the Sum and Average of Numbers Using Do-While Loop



Steps: 
  1.  Declare two integers i and n and also initialize i with 0.
  2. Declare three floats sum, avg and num and initialize sum with 0.
  3. Print the message on the screen to enter how many numbers want to find sum.
  4. Use do-while loop to insert the numbers calculate the sum and average.




Code:




#include<stdio.h>
#include<conio.h>



void main()
{

 int i=0,n;
 float sum, avg, num;

 clrscr();

 sum=0;

 printf("How many numbers you want to find sum and average\n");
 scanf("%d",&n);

 printf("Enter the numbers\n");

 do{
  scanf("%f", &num);
  sum=sum+num;
  i++;
 }

 while (i<n);

 avg=sum/n;

 printf("Sum=%f\n", sum);
 printf("Average=%f\n", avg);
 getch();
}




Related Posts:


continue reading

Write a Program in C to Sort a List of Numbers in Ascending Order


Program in C to Sort a List of Numbers in Ascending Order
In the program below nested  for loop is used to sort a list of  real numbers in ascending order. This program below asks to enter how many numbers want to sort and allow to enter the numbers to sort them in ascending order.
The nested for loop in the program swaps the numbers if first number is greater than the next number. i.e. using (a[j]>a[j+1]) and
       c=a[j];
       a[j]=a[j+1];
       a[j+1]=c;
Here the value of a[j] copied to c and value of a[j+1] copied to a[j] and then value of c is copied to a[j+1].



 Program in C to Sort a List of Numbers in Ascending Order



Steps:
  1. Declare an array with float to insert real numbers.
  2. Declare integers i, j, n, c and flag.
  3. Print the message to enter how many numbers want to insert and allow to enter the number.
  4.  Use for() loop to allow to enter the numbers to sort in ascending order.
  5. Use nested for() loop to to sort the list.
  6. Again use for() loop with printf() command to display the numbers on screen.



Code:



#include <stdio.h>
#include <conio.h>

void main()
{
float a[20];
int i,j,n,c,flag;

clrscr();

printf("how many numbers you want to enter:\n");
scanf("%d", &n);

printf("\Enter the numbers :\n");
for(i=0; i<n; i++)
scanf("%f", &a[i]);


for (i=0; i<n-1; i++)
{
	for(j=0; j<n-1-i; j++)
	{
		if(a[j]>a[j+1])
		{
			c=a[j];
			a[j]=a[j+1];
			a[j+1]=c;
			flag=0;
		}
	}
	if(flag)
	break;
	else
	flag=1;
}

printf("Stored elements:\n");
for(i=0; i<n; i++)
printf("%f\n", a[i]);
printf("\n");
getch();

}


 



Related Posts:


continue reading

Write a Program in C to Calculate the Factorial Value of an Integer.


Program in C to Calculate the Factorial Value of an Integer
Here is a program in C to calculate the factorial value of an integer.

The factorial of a number is the product of all the integers between 1 and that number.  For example factorial of 5 is 5*4*3*2*1. This can also be expressed as 5!=5*4!, where '!' stands for factorial.

Hence factorial of a number can also be programmed using recursion. Here I have given two methods for calculating factorial of a number, using non-recursive function and using recursive function.




Non-recursive function for calculating the factorial value of an integer

 

Steps:

  1. Declare prototype for the function named factorial() used to calculate factorial value.
  2. Declare two integers a and fact.
  3. Prompt the message to enter any number to calculate the factorial.
  4. Allow the user to enter number using scanf().
  5. Use function factorial() to calculate the factorial value and return that.
  6. Print the returned value to the screen using printf() command. 

 

code:


#include <stdio.h>


int factorial(int);


int main()
{
 int a, fact;

 printf("Enter any number");
 scanf("%d",&a);

 fact=factorial(a);
 printf("Factorial value-%d\n", fact);
 return 0;
}

int factorial(int x)
{
 int f=1,i;

 for(i=x;i>=1; i--)
 f=f*i;

 return(f);

}



Recursive function for calculating the factorial value of an integer


Steps:

 

  1. Declare prototype for the function named rec() used to calculate factorial value.
  2. Declare two integers a and fact.
  3. Prompt the message to enter any number to calculate the factorial.
  4. Allow the user to enter number using scanf().
  5. Use function rec() to calculate the factorial value using recursive method and return that.
  6. Print the returned value to the screen using printf() command. 

 


code:


#include <stdio.h>

int rec(int);
int main()
{
 int a, fact;

 printf("Enter any number");
 scanf("%d",&a);

 fact=rec(a);
 printf("Factorial value-%d\n", fact);
 return 0;
}

int rec(int x)
{
 int f;

 if(x==1)
  return(1);
 else
  f=x*rec(x-1);
 return(f);

}




continue reading

Write a Program in C to Copy a String to Another.


Here is a program in C to copy one string to another string using user defined function. Here two character arrays are defined then prompted to enter the strings and copied to the first string using while() function.

Program in C to Copy a String to Another



Program in C to Copy a String to Another



Steps:
  1. At first  declare two strings str1 and str2 and integers m, i, flag and j under main function.
  2. Prompt message to enter the strings and allow to enter strings using gets() function.
  3. Prompt the message and allow to enter the index where you want to insert in the first string.
  4. Copy second string to the first string using while() function.
  5. Print the first string to the screen.



Code:

#include <stdio.h>
#include <conio.h>

void main()
{
 char str1[20], str2[20];
 int m,i,flag=0,j;

 clrscr();

 printf("Enter the 1st String");
 gets(str1);
 printf("Enter the 2nd String");
 gets(str2);

 printf("Enter the index after which you want to insert 2nd string in 1st :");
 scanf("%d", &m);
 i=0;

 while (i<=m)
 {
 i++;
 }
 j=0;

 while (str2[j]!='\0')
 {
  str1[i]=str2[j];
  i++;
  j++;
  if (str1[i]=='\0')
  flag=1;
 }

 if (flag==1)
  str1[i]='\0';
  printf("%s", str1); 
                getch();
} 


continue reading

C Program to Read Set of Real Numbers from Keyboard & Find the Maximum


C Program to Read Set of Real Numbers and Find the Maximum
To write a C program to read set of real numbers from keyboard and find the maximum among them, you can use a function which takes an array of real numbers and its size as arguments and return the maximum.


Using this function you can write a program to read a set of real numbers from the keyboard and find the maximum number in the array.






C Program to Read Set of Real Numbers and Find the Maximum



Steps: 
  1. Define a function max() 
  2. Under main() function, declare two integers i and n.
  3. Declare an array a.
  4. Prompt the message to the user to insert how many elements they want to enter using printf() and allow to enter using scanf().
  5. Prompt the message and allow to enter the elements.
  6. Find out the maximum number among them using max() function.
  7. Print the maximum number along with message.

Code:


#include<stdio.h>
#include<conio.h>

max(float a[], int n);

void main()
{

int i,n;
float a[100];


 printf("\n How many elements you want to enter:\n");
 scanf("%d",&n);

 printf("\n Enter the elements:");
 for(i=0;i<n;i++)
 scanf("%f",&a[i]);
 max(a,n);
 getch();
}

max(float a[], int n)

{
 int i;
 float k, large;
 large=a[0];
 for (i=1;i<n;i++)
 {
  if (a[i]>large)
  {
   k=a[i];
   a[i]=large;
   large=k;
  }
 }

 printf("Largests element is :       %f", large);

return 0;

}


 

Related Posts: 


continue reading

Write a Program in C to Determine Whether a Number is Prime or Not.


Program in C to Determine Whether a Number is Prime or Not.
"A prime number is one, which is divisible only by 1 or itself."

To determine whether a number is prime or not, we have to divide the number successively by all numbers from 2 to one less than itself.

If remainder of any of these divisions is zero, the number is not a prime.

If no division yields a zero then the number is a prime number.



Program in C to Determine Whether a Number is Prime or Not


Steps:

  1. Declare integers num and i inside main()
  2. Prompt the message allow the input using printf() and scanf()
  3. Test whether a Number is prime or not using while() function.

Code:

#include <stdio.h>

int main()
 {

 int num, i;     


 printf("Enter a number");
 scanf ("%d",&num);

 i=2;

 while (i<=num-1)
 {

 if (num%i==0)
 {
  printf("Not a prime number\n");
  break;
 }

 i++;
 }

 if (i==num)

 printf("Prime number\n");

 return 0;
 }

continue reading

Solved MCQ of Data Warehouse set-3


OLAP Cube illustration
OLAP Cube illustration (Photo credit: Wikipedia)

1. Data warehouse architecture is based on .......................

A) DBMS

B) RDBMS

C) Sybase





2. .......................... supports basic OLAP operations, including slice and dice, drill-down, roll-up and pivoting.

A) Information processing

B) Analytical processing

C) Data mining

D) Transaction processing




3. The core of the multidimensional model is the ....................... , which consists of a large set of facts and a number of dimensions.

A) Multidimensional cube

B) Dimensions cube


D) Data model




4. The data from the operational environment enter ........................ of data warehouse.

A) Current detail data

B) Older detail data

C) Lightly Summarized data

D) Highly summarized data


continue reading

MCQ on Data Warehouse with Answers set-2


Data Warehouse Overview
Data Warehouse Overview (Photo credit: Wikipedia)


1. The full form of OLAP is


A) Online Analytical Processing

B) Online Advanced Processing

C) Online Advanced Preparation

D) Online Analytical Performance




2. ......................... is a subject-oriented, integrated, time-variant, nonvolatile collection or data in support of management decisions.

A) Data Mining

B) Data Warehousing

C) Document Mining

D) Text Mining




3. The data is stored, retrieved and updated in ....................

A) OLAP

B) OLTP

C) SMTP

D) FTP




4. An .................. system is market-oriented and is used for data analysis by knowledge workers, including managers, executives, and analysts.

A) OLAP

B) OLTP

C) Both of the above

D) None of the above



continue reading

MCQ on Data Mining with Answers set-1



1. ...................... is an essential process where intelligent methods are applied to extract data patterns.


MCQ on Data Mining with AnswersA) Data warehousing

B) Data mining

C) Text mining

D) Data selection



2. Data mining can also applied to other forms such as ................


i) Data streams

ii) Sequence data

iii) Networked data

iv) Text data

v) Spatial data

A) i, ii, iii and v only

B) ii, iii, iv and v only

C) i, iii, iv and v only

D) All i, ii, iii, iv and v



3. Which of the following is not a data mining functionality?

A) Characterization and Discrimination

B) Classification and regression

C) Selection and interpretation

D) Clustering and Analysis



4. ............................. is a summarization of the general characteristics or features of a target class of data.

A) Data Characterization

B) Data Classification

C) Data discrimination

D) Data selection


continue reading

Solved Objective Questions for IT Officer Exam Part-3


Network topology Mesh topology
Mesh topology (Photo credit: Wikipedia)

1. What is the name of the network topology in which there are bi-directional links between each possible node?

A) Ring


B) Star

C) Tree

D) Mesh




2. Which scheduling policy is most suitable for time-shared operating system?

A) Shortest job first

B) Round-robin

C) Elevator

D) First-come-first-serve



3. A next-generation web content development language, ................ typically refers to a suite of technologies that allow developers to store data in a readable format.

A) HTML

B) XML

C) XSL

D) PHP



4. A(n) ................... is a private corporate network that uses standard Internet protocols and interfaces.

A) Internet

B) Extranet

C) Local Area Network

D) Intranet



5. Integrated Circuit is related to .......................... generations computers.

A) Second

B) Third

C) Fourth

D) Fifth


continue reading

Solved MCQ for IT Officer Exam Part-2


SWIFT Logo
SWIFT Logo (Photo credit: Wikipedia)
1. SWIFT stands for:

A) Society for Worldwide Interbank Financial Telecommunication

B) Society for Worldwide International Financial Telecommunication

C) Society for Worldwide Interbank Financial Transmission

D) Society for Worldwide Interbank Financial Transfer



2. Which one is the correct statement?

A) XML is a technology used only on the internet.

B) XML is a programming language.

C) XML is highly suitable data exchange between two different systems.

D) XML is scripting language.



3. Decision support systems usually

A) serve managers interested in weekly, monthly and yearly results, not day-to-day activities.

B) help managers make decisions that are unique, rapidly changing and not easily specified in advance.

C) provide managers with a generalized computing and telecommunications capacity that can be applied to a changing array of problems.

D) perform and record the daily routine transactions necessary to the conduct of business.



4. Identifying customers and markets using data on demographics, markets, consumer behavior and trends is an example of a (n):

A) operational-level sales and marketing information system

B) knowledge-level sales and marketing information system

C) strategic-level sales and marketing information system

D) management-level sales and marketing information system



5. Enterprise systems support:

A) manufacturing process

B) financial and accounting process

C) human resource processes

D) all of the above


continue reading

How to Delete Browsing History From Browser ?


As you browse the web, browsers can remember lots of information such as the website you have visited, files you have downloaded and other more, such information are called browsing history. Most of the web browsers stores information on their browsing history, if you are using public computer or a shared computer and want to delete browsing history from computer, can do it with different methods. Here I have explained different methods for deleting browsing history from different browsers
.

Deleting Browsing History From Control Panel



1. Go to control panel from start button. If you are viewed by category option, Click on Network and Internet option. 

Deleting Browsing History From Control Panel



















continue reading