MCQ on Core Java with Answers set-13



1. Which exception is thrown by the read( ) method of input stream class?

A) Exception

B) ClassNotFoundException

C) read Exception

D) IOException



2. What garbage collection in the context of java?

A) The operating system periodically deletes all of the java files available on the system.

B) Any package imported in a program and not used in automatically deleted.

C) When all references to an object are gone, the memory used by the object is automatically reclaimed.

D) The JVM checks the output of any Java program and deletes anything that doesn't make sense.



3. In order for a source code file, containing the public class test, to successfully compile, which of the following must be true?

A) It must have a package statement

B) It must be named test.java

C) It must import java.lang

D) It must declare a public class named test.



4. Which of the following are true about the Error and Exception classes?

A) Both classes extend throwable

B) The error class is final and exception class is not.

C) The Exception class is final and the Error is not.

D) Both classes implement Throwable



5. Which of the following are true?

A) The void class extends the class class

B) The float class extends double class

C) The system class extends the runtime class

D) The integer class extends the number class



6. How do you create a Reader object from an InputStream object?

A) Use the static createReader() method of InputStream class

B) Use the static createReader() method of Reader class

C) Create an InputStreamReader object passing the InputStream object an an argument to the InputStreamReader constructor.

D) Create an OutputStreamReader object, passing the InputStream object as an argument to the OutputStreamReader constructor.



7. Which of the following is true?

A) The event inheritance model has replaced the event delegation model

B) The event inheritance model is more efficient than event delegation model

C) The event delegation model uses event listeners to define the methods of event handling classes.

D) The event delegation model uses the handleEvent() method to support event handling.



8. Which of the following is the highest class in the event delegation model?

A) java.util.EventListner

B) java.util.EventObject

C) java.util.AWTEvent

D) java.util.event.AWTEvent



9. When two or more objects are added as listeners for the same event, which listener is first invoked to handle the event?

A) The first object that was added as listner.

B) The last object that was added as listner

C) There is no way to determine which listener will be invoked first.

D) It is impossible to have more than one listener for a given event.



10. Suppose that you want to have an object eh handle the TextEvent of TextArea object t. How should you add eh as the event handler for?

A) t.addTextListener(eh);

B) eh.addTextListner(t);

C) addTextListner(eh.t);

D) addTextListner(t,eh);



11. What is the preferred way to handle an object's events in Java 2?

A) Override the object's handleEvent( ) method.

B) Add one or more event listeners to handle the events

C) Have the object override its process Event( ) methods.

D) Have the object override its dispatch Event( ) methods.



12. Which component method is used to access a component's immediate container?

A) getVisible()

B) getImmediate()

C) getParent()

D) getContainer()



13. Which of the following creates a List with 5 visible items and multiple selection enabled?

A) new List(5, true)

B) new List(true, 5)

C) new List(5, false)

D) new List(false, 5)



14. An Applet has its Layout Manager set to the default of FlowLayout. What code would be the correct to change to another Layout Manager?

A) setLayoutManager(new GridLayout());

B) setLayout(new GridLayout(2,2));

C) setGridLayout(2,2);

D) setBorderLayout();



15. How do you change the current layout manager for a container?

A) Use the setLayout method.

B) Once created you cannot change the current layout manager of a component

C) Use the setLayoutManager method.

D) Use the updateLayout method.



16. Which of the following methods can be used to draw the outline of a square within a JAVA.awt.Component object?

A) drawLine()

B) fillRect()

C) drawPolygon()

D) drawPolygon()



17. State true or false

i) JPanel is a class included in awt package

ii) Anonymous classes are mostly used for event handling

iii) Names of anonymous classes must be unique

iv) JOptionPane is an inner class

A) i-false, ii-false, iii-true, iv-true

B) i-true, ii-false, iii-true, iv-false

C) i-false, ii-true, iii-false, iv-false

D) i-true, ii-true, iii-false, iv-true



18. State true or false

i) Java RMI supports distributed objects written entirely in java

ii) Java RMI makes use of stubs and skeleton

iii) In Java RMI an object registers itself with a media server

iv) IDL is interface declaration language

A) True, True, False, False

B) False, True, True, True

C) True, False, True, False

D) True, True, True, True



19. Match the following

a) Datagram Socket        i) UDP connection

b) URL                           ii) provides necessary framework of debugging java programs

c) java.net                      iii) makes it possible to communicate over a network with java programs

d) sun.tools.debug          iv) is a java object that represent WWW address

A) a-i, b-iv, c-iii, d-ii

B) a-i, b-iv, c-ii, d-iii

C) a-ii, b-iii, c-i, d-iv

D) a-ii, b-i, c-iii, d-iv



20. State true or false

i) public can only be assigned to class

ii) protected protects a statement

iii) protected method is never accessible outside the package

iv) friendly variable may be accessible outside class

A) True, True, False, True

B) False, False, False, True

C) False, True, False, False

D) True, False, False, False


View Answers:


1. D) IOException
2. C) When all references to an object are gone, the memory used by the object is automatically reclaimed
3. B) It must be named test.java
4. A) Both classes extend throwable
5. D) The integer class extends the number class
6. C) Create an InputStreamReader object passing the InputStream object an an argument to the InputStreamReader constructor.
7. C) The event delegation model uses event listeners to define the methods of event handling classes.
8. B) java.util.EventObject
9. C) There is no way to determine which listener will be invoked first.
10. D) addTextListner(t,eh);
11. B) Add one or more event listeners to handle the events
12. C) getParent()
13. A) new List(5, true)
14. B) setLayout(new GridLayout(2,2));
15. A) Use the setLayout method
16. A) drawLine()
17. C) i-false, ii-true, iii-false, iv-false
18. A) True, True, False, False
19. A) a-i, b-iv, c-iii, d-ii
20. A) True, True, False, True




Related Posts:



continue reading

MCQ on Java Programming Language Fundamental set-12



1. A java program is first ................ and ...................

A) executed, run

B) compiled, run

C) run, compiled

D) interpreted, compiled


2. Byte code is also a ...........

A) machine code

B) bit code

C) cryptographic code

D) none


3. A private class is accessible from inside a .................

A) package

B) class

C) method

D) none


4. Consider the statement "x=(a>b)?a:b", then the value of x is 19, if a=19 and b=12

A) true

B) not supported

C) false

D) none of the above


5. Adapter classes are used for ...............

A) code redundancy

B) code reduction

C) code organization

D) none


6. ..................... inheritance is enable by interface in java.

A) min level

B) multiple

C) low level

D) none


7. .................... is generated if a button is clicked in AWT.

A) ItemEvent

B) WindowEvent

C) ActionEvent

D) MouseEvent


8. Using which keyword we can access value of the instance and class variables of that class inside the method of that class itself.

A) super

B) final

C) this

D) either super or this


9. If a variable is declared FINAL, it must include ......................... value.

A) integer

B) number

C) initial

D) float


10. In java, string is a

A) primitive data type

B) abstract data type

C) combination of boolean

D) None of the above


11. Methods can be overloaded with a difference only in the type of the return value

A) Not supported

B) False

C) True

D) None of the above


12. Each method in a java class must have a unique name

A) Not necessarily

B) True

C) False

D) None of the above


13. It is an important feature of java that it always provides a default constructor to a class

A) Not supported

B) False

C) True

D) None of the above


14. If one or more abstract methods are not implemented in an abstract class, then the subclass is also abstract.

A) Not necessarily

B) False

C) True

D) None of the above


15. Life cycle of an applet is described by .................. methods.

A) six

B) three

C) four

D) five


16. Which of the following is not subclass of "writer" stream.

A) FileWriter

B) LineWriter

C) BufferedWriter

D) PrintWriter


17. In java RMI, stub is located in

A) client machine

B) proxy

C) server

D) none of the above


18. The new keyword will

i) create in instance of an object

ii) create instance of a class

iii) assign memory to an array

iv) call the destructor of a class

A) i and iii

B) ii and iii

C) i and ii

D) ii, iii and iv


19. ODBC stands for

A) Object Data Binding Command

B) Open Database Console

C) Open Database Connectivity

D) Open Database Command


20. Continue statement can be used

i) anywhere inside main method

ii) anywhere inside class

iii) within instance methods

iv) only within looping statements

A) i, ii and iii

B) i and iv

C) only iv

D) ii, iii and iv





Show/Hide Answers:




1. A java program is first ................ and ...................

B) compiled, run

2. Byte code is also a ...........

D) none

3. A private class is accessible from inside a .................

B) class

4. Consider the statement "x=(a>b)?a:b", then the value of x is 19, if a=19 and b=12

A) true

5. Adapter classes are used for ...............

B) code reduction

6. ..................... inheritance is enable by interface in java.

B) multiple

7. .................... is generated if a button is clicked in AWT.

C) ActionEvent

8. Using which keyword we can access value of the instance and class variables of that class inside the method of that class itself.

C) this

9. If a variable is declared FINAL, it must include ......................... value.

C) initial

10. In java, string is a

B) abstract data type

11. Methods can be overloaded with a difference only in the type of the return value

B) False

12. Each method in a java class must have a unique name

A) Not necessarily

13. It is an important feature of java that it always provides a default constructor to a class

C) True

14. If one or more abstract methods are not implemented in an abstract class, then the subclass is also abstract.

C) True

15. Life cycle of an applet is described by .................. methods.

C) four

16. Which of the following is not subclass of "writer" stream.

B) LineWriter

17. In java RMI, stub is located in

A) client machine

18. The new keyword will

i) create in instance of an object

ii) create instance of a class

iii) assign memory to an array

iv) call the destructor of a class

A) i and iii

B) ii and iii

C) i and ii

D) ii, iii and iv

19. ODBC stands for

A) Object Data Binding Command

B) Open Database Console

C) Open Database Connectivity

D) Open Database Command

20. Continue statement can be used

i) anywhere inside main method

ii) anywhere inside class

iii) within instance methods

iv) only within looping statements

C) only iv



Related Posts:


continue reading

MCQ on Basic SQL Queries with Answers set-1



1. DML is provided for

A) Description of logical structure of database

B) Addition of new structure in the database system.

C) Manipulation & processing of database

D) Definition of physical structure of database system


2.'AS' clause is used in SQL for

A) Selection operation

B) Rename Operation

C) Join operation

D) Projection Operation


3. Count function in SQL returns the number of

A) values

B) distinct values

C) groups

D) columns


4. The statement in SQL which allows to change the definition of a table is

A) Alter

B) Update

C) Cteate

D) Select


5. Which of the following is correct.

A) A SQL query automatically eliminates duplicates

B) SQL permits attribute names to be repeated in the same relation

C) A SQL query will not work if there are no indexes on the relations

D) None of the above


6. Which of the following operation is used if we are interested in only certain columns of a table?

A) PROJECTION

B) SELECTION

C) UNION

D) JOIN


7. Which of the following is a legal expression in SQL?

A) SELECT NULL FROM EMPLOYEE;

B) SELECT NAME FROM EMPLOYEE;

C) SELECT NAME FROM EMPLOYEE WHERE SALARY=NULL;

D) None of the above


8. Which of the following is a valid SQL type?

A) CHARACTER

B) NUMERIC

C) FLOAT

D) All of the above


9. Which command is used to select distinct subject (SUB) from the table (BOOK)?

A) SELECT ALL FROM BOOK

B) SELECT DISTINCT SUB FROM BOOK

C) SELECT SUB FROM BOOK

D) All of the above


10. In SQL, which of the following is not a data definition language commands?

A) RENAME

B) REVOKE

C) GRANT

D) UPDATE



continue reading

Solved MCQ on Database Normalization set-1




1. A ..................... specifies the actions needed to remove the drawbacks in the current design of database.

A) 1 NF

B) 2 NF

C) 3 NF

D) Normal form



2. A relation is in ........................... if an attribute of a composite key is dependent on an attribute of other composite key.

A) 2NF

B) 3NF

C) BCNF

D) 1NF



3. Fifth Normal form is concerned with

A) Functional dependency

B) Multivalued dependency

C) Join dependency

D) Domain key



4. A table is in the ....................... if only candidate keys are the determinants.

A) functional dependency

B) transitive dependency

C) 4 NF

D) BCNF



5. In 2NF

A) No functional dependencies exist.

B) No multivalued dependencies exist.

C) No partial functional dependencies exist

D) No partial multivalued dependencies exist.


6. The normal form that is not necessarily dependency preserving is

A) 2NF

B) 3NF

C) BCNF

D) 4NF



7. The ................. is related to the concept of multi-valued dependency.

A) fourth normal form

B) fifth normal form

C) boyce codd normal form

D) third normal form



8. Which normal form is considered adequate for normal relational database design?

A) 2NF

B) 5NF

C) 4NF

D) 3NF



9. Dependency preservation is not guaranteed in

A) BCNF

B) 3NF

C) 4NF

D) DKNF



10. A relation is ................... if every field contains only atomic values that is, no lists or sets.

A) 1 NF

B) 2 NF

C) 3 NF

D) BCNF



Answers:



1. A ..................... specifies the actions needed to remove the drawbacks in the current design of database.

D) Normal form

2. A relation is in ........................... if an attribute of a composite key is dependent on an attribute of other composite key.

B) 3NF

3. Fifth Normal form is concerned with

C) Join dependency

4. A table is in the ....................... if only candidate keys are the determinants.

D) BCNF

5. In 2NF

C) No partial functional dependencies exist

6. The normal form that is not necessarily dependency preserving is

A) 2NF

7. The ................. is related to the concept of multi-valued dependency.

A) fourth normal form

8. Which normal form is considered adequate for normal relational database design?

D) 3NF

9. Dependency preservation is not guaranteed in

A) BCNF

10. A relation is ................... if every field contains only atomic values that is, no lists or sets.

A) 1 NF





 Related Posts:



continue reading

Solved MCQ on C++ Programming Language set-7



1. What is required in inheritance to initialize the data members of the base class through derived class?

A) Object declaration

B) Destructor

C) Constructor

D) Inheritance


2. In which case is it mandatory to provide a destructor in a class?

A) Almost in every class

B) Class for which two or more than two objects will be created

C) Class for which copy constructor is defined

D) Class whose objects will be created dynamically


3. Which of the statements is true in a protected derivation of a derived class from a base class?

A) Private members of the base class become protected members of the derived class

B) Protected members of the base class become public members of the derived class

C) Public members of the base class become protected members of the derived class

D) Protected derivation does not affect private and protected members of the derived class


4. When the access specifier of the base class in the derived class definition is public, the base class is ..

A) Publicly inherited

B) Protectedly inherited

C) Privately inherited

D) None of the above


5. A pointer to the base class can hold address of

A) only base class object

B) only derived class object

C) base class object as well as derived class object

D) None of the above


6. A template class

A) is designed to be stored in different containers

B) works with different data types

C) generates objects which must be identical

D) generates classes with different numbers functions


7. The constructor and the destructor of a class are automatically invoked when memory is allocated and deallocated to an ....

A) Data type

B) Copy constructor

C) Object

D) None of the above


8. A pure virtual function is a virtual function that

A) has no body

B) returns nothing

C) is used in base class

D) both (A) and (C)


9. A class defined within another class is

A) Nested Class

B) Inheritance

C) Containership

D) Encapsulation


10. Which variable stores the memory address of another variable?

A) Reference

B) Pointer

C) Array

D) None of the above



continue reading

MCQ on c++ Programming with Answers set-6



1. If a class C is derived from class B, which is derived from class A, all through public inheritance, then a class C member function can access.

A) Protected and public data only in C and B

B) Protected and public data only in C

C) Private data in A and B

D) Protected data in A and B


2. Overloading the function operator

A) requires a class with an overloaded operator

B) requires a class with an overloaded [ ] operator.

C) allows you to create objects that act syntactically like functions.

D) usually make use of a constructor that takes arguments.


3. What is a constructor?

A) A function called when an instance of a class is initialized.

B) A function that is called when an instance of a class is deleted.

C) A special function to change the value of dynamically allocated memory

D) A function that is called in order to change the value of a variable.


4. Mechanism of deriving a class from another derived class is known as .........

A) Polymorphism

B) Single Inheritance

C) Multilevel Inheritance

D) Message Passing


5. RunTime Polymorphism is achieved by ..........

A) friend function

B) virtual function

C) operator overloading

D) function overloading


6. Which of the following is the proper declaration of a pointer?

A) int x;

B) int &x;

C) ptr x;

D) int *x;


7. In multiple inheritance

A) the base classes must have only default constructors

B) cannot have virtual functions

C) can include virtual classes

D) None of the above


8. for (; ;)

A) means the test which is done using some expression is always true

B) is not valid

C) will loop forever

D) should be written as for( )


9. The compilers converts all operands upto to type of the largest operand is called as ............

A) typeconversion

B) expression

C) evaluation

D) precedence


10. The keyword FRIEND does not appear in

A) the class allowing access to another class

B) the class desiring access to another class

C) the private section of a class

D) the public section of a class



continue reading

objective type questions in c programming language set-6




1. Which symbol is used as a statement terminator in C?

A) !

B) ~

C) #

D) ;


2. If the size of the array is less than the number of initializes then, ..........

A) extra values are being ignored

B) generates an error message

C) size of array is increased

D) size is neglected when values are given


3. In C, if you pass an array as an argument to a function, what actually gets passed?

A) Value of elements in array

B) First element of the array

C) Base address of the array

D) Address of the last element of array


4. How many times the following loop be executed? { .. ch='b'; while (ch>='a' && ch<=='z') ch++; }

A) 0

B) 25

C) 26

D) 1


5. If a=8 and b=15 then the statement x=(a>b) ? a:b;


A) assigns a value 8 to x

B) gives an error message

C) assigns a value 15 to x

D) assigns a value 7 to x


6. What is the output of the following code. int n=0, m=1; do { printf("%d", m); m++; } while (m<=n);

A) 0

B) 2

C) 1

D) 4


7. A C program contains the following declaration int i=8, j=5 what would be the value of following expression? abs(i-2*j)
A) 2

B) 4

C) 6

D) 8


8. The output of the following is . int a=75; printf("%d%%", a);

A) 75

B) 75%%

C) 75%

D) None of the above


9. How many times the following program would print ("abc")? main( ) { printf("\nabc"); main( ); }

A) Infinite number of times

B) 32767 times

C) 65535 times

D) Till the stack does not overflow


10. Which of the following is the correct usage of conditional operators used in C?

A) a>b?c=30:c=40;

B) a>b?c=30;

C) max=a>b?a>c?a:c:b>c?b:c

D) return (a>b)?(a:b)



continue reading

Solved MCQ on C Programming Language set-5



1. What will be output of the following C program? #include int main() {int goto=5; printf("%d",goto); return 0;}

A) 5

B) 10

C) **

D) compilation error


2. Output of the following C program fragment is. x=5; y=x++; printf("%d %d", x,y);

A) 5, 6

B) 5, 5

C) 6, 5

D) 6, 6


3. What will be output of the following C program? #include int xyz=10; int main() { int xyz=20; printf("%d", xyz); return 0;}

A) 10

B) 20

C) 30

D) compilation error


4. Following program fragment. main(){ printf("%p\n", main( ) ); }

A) Prints the address of main function

B) Prints 0

C) Is an error

D) In an infinite loop


5. What will be output of the following program? #include int main() {int a=2, b=7, c=10; c=a==b; printf("%d",c); return 0;}

A) 0

B) 7

C) 10

D) 2


6. What is the output of the following program segment? main( ) { long i=65536; printf("%d\n", i); }

A) 0

B) 65536

C) -1

D) 65


7. What will be the output of the program? # include int main() {int a[5]={5,1,15,20,25}; int i, j, m; i=++a[1]; j=a[1]++; m=a[i++]; printf("%d, %d, %d", i,j,m); return0;}

A) 2, 1, 15

B) 1, 2, 5

C) 3, 2, 15

D) 2, 3, 20


8. What is the output of the following program segment? main( ) { int=1; do { printf("%d . . ", i); } while (i--); }

A) 0 . . 1 . .

B) 1 . . 0 . .

C) 0

D) -1


9. Output of the program below is. int i; main( ) { printf("%d", i); }

A) 1

B) 0

C) -1

D) Null


10. What will be the output of the following program? main( ) { int i=5; printf("%d", i=++i==6); }

A) 0

B) 7

C) 6

D) 1

continue reading

MCQ on C Programming With Answers set-4



1. 'C' is often called a ....

A) Object oriented language

B) High level language

C) Assembly language

D) Machine level language


2. Each C preprocessor directive begins with ....

A) #

B) include

C) main()

D) {


3. C allows arrays of greater than two dimensions, who will determine this?

A) programmer

B) compiler

C) parameter

D) None of the above


4. The << operator is used for

A) Right shifting

B) Left shifting

C) Bitwise shifting

D) Bitwise complement


5. Set of values of the same type, which have a single name followed by an index is called

A) function

B) structure

C) array

D) union


6. Which of the following header file is required for strcpy() function?

A) String.h

B) Strings.h

C) file.h

D) strcpy()


7. scanf() can be used for reading ...

A) double character

B) single character

C) multiple characters

D) no character


8. A variable which is visible only in the function in which it is defined is called

A) Static variable

B) auto variable

C) external variable

D) local variable


9. In the loop structure logical expression is checked at the ....................of the loop.

A) first

B) end

C) middle

D) second


10. If an array is used as function argument, the array is passed

A) by value

B) by reference

C) by name

D) the array cannot be used as function argument


11. If is necessary to declare the type of function in the calling program if

A) Function returns an integer

B) Function returns a non-integer value

C) Function is not defined in the same file

D) Function is called number of times


12. Which escape character can be used to begin a new line in C ........

A) \a

B) \m

C) \b

D) \n


13. Input/output function prototypes and macros are defined in which header file?

A) conio.h

B) stdlib.h

C) stdio.h

D) dos.h


14. What is the purpose of fflush() function?

A) flushes all streams and specified streams

B) flushes only specified stream

C) flushes input/output buffer

D) flushes file buffer


15. What does the following declaration mean?int(*ptr)[10].

A) ptr is array of pointers to 10 integers.

B) ptr is a pointer to an array of 10 integers

C) ptr is an array of 10 integers

D) ptr is an pointer to array



continue reading

How to validate required field in a form using javascript


In a wave form, fields are needs to validate at the time of entry or on submission of form. Generally in a form it needs to validate user has left required fields empty or not, user has entered valid e-mail address or not, user has entered a valid date, user has entered text in a numeric field or not and other also. 

Here is a function below to validate if a required field has been left empty. If the required field is blank, an alert box alerts a message and the function returns false. If a value is entered, the function returns true.


 Function to validate required field in a form using javascript


function validate_required(field, alerttxt)
{
with (field)
{
if (value==null||value=="")
	{alert(alerttxt); return false}
else {return true}
}
}

Full script, with the HTML form to validate required field 

<!DOCTYPE html>
<html>
<head>
<script>
function validate_required(field, alerttxt)
{
with (field)
{
if (value==null||value=="")
	{alert(alerttxt); return false}
else {return true}
}
}

function validate_form(thisform)
{
with(thisform)
{
if(validate_required(email, "Email must be filled out!")==false)
	{email.focus();return false}
}
}
</script>
</head>

<body>
<form action="submitpage.htm" onsubmit="return validate_form(this)" method="post">
Email:<input type="text" name="email" size="40">
<input type="submit" value="submit">
</form>
</body>

</html>

Preview of the above code, to validate required field 


continue reading

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





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