0% found this document useful (0 votes)
4 views

java_mcq-1

The document contains a series of objective type questions related to Java programming concepts, including object-oriented programming principles, Java's features, data types, and operators. Each question provides multiple-choice answers, testing knowledge on topics such as inheritance, encapsulation, and the Java Virtual Machine. The questions are structured to assess understanding of Java syntax, data representation, and programming logic.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

java_mcq-1

The document contains a series of objective type questions related to Java programming concepts, including object-oriented programming principles, Java's features, data types, and operators. Each question provides multiple-choice answers, testing knowledge on topics such as inheritance, encapsulation, and the Java Virtual Machine. The questions are structured to assess understanding of Java syntax, data representation, and programming logic.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

I.

Objective Type Questions:


1. The process that allows us to perform a single action in different ways is called:
A) Abstraction C) Inheritance B) Polymorphism D) Encapsulation

2. A feature of Java programming that lets you create classes that are derived from other classes is called:
A) Polymorphism C) Inheritance B) Encapsulation D) Abstraction

3. A class inheriting from other class and adding its own methods to it is called:
A) Abstract class B) Super class C) Sub class D) Main class

4. An object is a/an ____ of a class:


A) child B) interface C) instance D) parent

5. The state of an object is represented by:


A) Value of attributes C) Value of arguments B) Value of parameters D) Abstraction

6. Hiding the implementation details and showing only functionality to the user is called:
A) Abstraction B) Inheritance C) Encapsulation D) Polymorphism

7. Pick the incorrect statement.


A) A class is a collection of similar type of objects
B) A class is a blue print of an object
C) A class is a user-defined data type
D) Only one instance can be created from a class

8. The term object is often interchangeable with:


A) attribute B) instance C) methods D) interface

9. In Procedure Oriented Programming abstraction is at:


A) Function level B) Package level C) Compiler level D) Object level

10. Select the correct option:


A) An object has attributes B) An object has behaviour C) An object has a state D) All of the above

11. The acronym OOP stands for

A. Object Oriented Procedure B. Object Oriented Packet


C. Object Orientation Procedure D. Object Oriented Programming

12. The OOP mainly uses

A. Top-down approach B. Bottom-up approach C. Top and Bottom Approach D. None of the above

13. What represents an entity in the real-world with its identity and behaviour.
A. method B. A class C. A procedure D. An object

14. An object has:


A. Attributes B. Behaviour C. State D. All of the above

15. An object belonging to a particular class is known as a/an ------ of that class.
A. Instance B. Alias C. Interface D. Member

16. Procedure Oriented Programming mainly uses:


A. Bottom-up approach B. Top-down approach C. Top-down and bottom-up approach D. None of the above

17. A class is:


A. A specification for objects B. An object factory C. A blueprint to create objects D. All of the above

18. Which option is the technique of binding both data and methods together to keep them safe from unauthorised access
and misuse?
A. Abstraction B. Encapsulation C. Polymorphism D. Inheritance

19. The ability of a method or object to take on multiple forms is known as:
A. Polymorphism B. Encapsulation C. Abstraction D. Inheritance
20. Objects that share the same attributes and behaviour are grouped together into a/an:
A. Alias B. Interface C. Instance D. Class

21. A feature that enables one class to acquire the properties of another class:
A. Encapsulation B. Abstraction C. Inheritance D. Polymorphism

22. Procedure Oriented Programming gives importance to:


A. Data only B. Instructions only C. Instructions and data D. None of the above

23. Which option servers as a template to create similar objects that share common characteristics and behaviour?
A. An attribute B. A method C. A class D. A procedure

24. Which option refers to the act of representing essential features without including the background details?
A. Abstraction B. Encapsulation C. Inheritance D. Polymorphism

25. The values of an object’s -------- represent the state of the object.
A. attributes B. methods C. classes D. procedures

Part 2 - Introduction to Java

1.A virtual machine that executes Java bytecode is called:


A)javac B)Java assembler C)OOP D) JVM

2.Machine language for Java Virtual Machine is called:


A)JVM B) Bytecode C)Java platform D)Java compiler

3.Java language is:


A)Multithreaded B)Object Oriented C)Platform independent D)All of the above

4.Pick the correct statement:


A)Java uses interpreter only B)Java uses compiler only C)Java uses compiler and interpreter D)None

5.Pick the correct statement:


A)A compiler translates code into high-level language all at once
B)A compiler translates code into machine language one line at a time
C)An interpreter translates code into machine language all at once
D)An interpreter translates code into machine language one line at a time

6.A machine language version of the code is called:


A)Object Code B)High Level Code C)Source Code D)Main Method Code

7. A computer only understands


A.High-level language B.Assembly language C.English language D.Machine language

8.A computer program’s capability to run on multiple operating systems is called:


A)Multiuser program B) Platform dependence C) Platform independence D) Multilingual program

9.The file extension of a Java class file is:


A. class B.doc C.bluej D. java

10. What does a stand-alone Java application need for execution?


A. A Java-compatible web browser
B. Does not need a Java-compatible web browser
C. Needs an Assembler
D. Needs an Object Linker

11. The acronym JIT in JIT Compiler stands for


A. Just In Transfer B. Java Input Terminal C. Just In Time D. Java Input Token
12. The acronym JRE stands for
A. Java Routine Enabler
B. Java Runtime Environment
C. Java Robust Editor
D. Java Runtime Execution

13. Which statement is true?


A. Java application can run on Windows platform only
B. Java applications are platform dependent
C. Java applications are platform independent
D. Java applications don’t need a platform to run

14. A computer program that translates a high-level language program into machine code is:

A. Linker B. Assembler C. Library D. Compiler

15. Pick the correct answer:

A. An applet can be executed in an Applet Viewer and Web Browser


B. An applet can be executed in an Applet Viewer only
C. An applet can be executed in a Web Browser only
D. An applet cannot be executed on a computer

16. A computer program that translates an assembly language program into machine code is:

A. Linker B. Assembler C. Library D. Compiler

17. The File extension of java program


A. .class B. . doc C. .bluej E. .java

18. Which statement is true?


A. Java applications can run on Windows
B. Java applications can run on Mac
C. Java applications can run on Linux
D. All of the above

19. The acronym JVM stands for


A. Java Virtual Motor B. Java Virtual Monitor C. Java Virtual Mode D. Java Virtual Machine

20. For a Java program to run as a stand-alone program it must have:


A. a main method B. a virtual method C. a protected method D. an overloaded method

Values and Data Types

1.Abbreviation ASCII stands for:


A)American Standard Code for Interface Implementation
B)American Standard Computer for Information Interchange
C)American Standard Computer for Intelligent Interface
D)American Standard Code for Information Interchange

2.Which character set would you use if you have characters from Hindi, Japanese and German to display?
A)ASCII Character Set B)Unicorn Character Set
B)Extended ASCII Character Set D)Unicode Character Set

3.ASCII character set can represent:


A)127 different characters B)128 different characters C)256 different characters D)Any number of characters

4.Which one is an invalid Escape Sequence?


A)/n B)/a C)/t D)All of the above

5.Which one is not a keyword in Java?


A)abstract B)integer C)class D)long
6.Which one is a valid identifier in Java?
A)total amount C)total_percentage_% B)total-amount D) total_amount

7.Which one is a valid integer literal?


A) -7777 B) 77 38 C)56,234 D)$788

8.Which one is a valid real literal?


A) 65. B).65 C)65 D)65.6

9.Which of the following is not a character literal?


A) ‘\a’ B) “a” C)‘a’ D)‘\?’

10.Which one is not a reference data type in Java?


A)class B)interface B) boolean D) class

11. Which of the following is the size of short data type in Java?
A) 8 bits B) 24 bits C) 16 bits D) 32 bits

12. Which of the following is the size of char data type in Java?
A) 8 bits B) 24 bits C) 16 bits D) 64 bits

13. Given statement int x = ‘Z’; What is the value of x? ( As ASCII value for A = 65, B = 66,…..Z =90 )
( ASCII value for a = 97, b = 98 ,………z=122 )
A) 90 B) 65 C) 91 D) Invalid assignment

14. Which of the following is default initial value of a boolean datatype?


A) true B) false B) null D) void

15. The keyword that converts a variable with its value into a constant is:
A) const B) constant C) fixed D) final

16. The smallest individual unit in a program is:


A) Identifier B) Token C) Method D) Function

17. Which statement is incorrect?


A) You can assign a value to the variable at the time of declaration
B) You can declare a variable and initialise it separately
C) You can assign values to multiple variables in one statement
D) When declaring a variable, you cannot assign an initial value that is an expression

18. Which statement is incorrect about naming identifiers in Java?


A) An identifier can consist of any number of letters and digits
B) An identifier can begin with an underscore
C) An identifier can begin with a digit
D) An identifier can begin with a dollar sign

19. Name the data type that is a 64-bit integer:


A) int B) float C) double D) long

20. Arrange the following primitive data types in the ascending order of size:
A) byte, char, int, double B) char, byte, int, double
C) byte, char, double, int D) char, byte, int, double

21. Pick the correct statement


A) char data type occupies 2 bytes and the int data type occupies 4 bytes
B) char data type occupies 4 bytes and the int data type occupies 2 bytes
C) both char and int data type occupy 2 bytes
D) both char and int data type occupy 4 bytes

22. Which of the following is a keyword?


A) keyword B) attribute C) character D) continue
23. ASCII codes of a-z are represented by decimal range:
A) 97-122 B) 65-91 B) 98-123 D) 65-92

24. Which of these is not a character literal?


A) “\t” B) ‘\t’ B) ‘t’ D) None of the above

25. Which of the following is not integral data type?


A) byte B) long C) short D) double

Part 4 - Operators in Java

1. Which form of Operators are supported in Java?


A)Unary Operators B)Binary Operators C)Ternary Operators D)All of the above

2.Which of the following is not a binary operator?


A) / B)OR C)++ D)=

3.Which of the following is not a valid operator in Java?


A)% B)-- C)++ D)=!

4. Statement i = i -1 is equivalent to
A)i-- B) - -i C) i -= 1 D)All of the above

5.Given z = 4, the statement x = ++z + 4 evaluates to


A)8 B)9 C)10 D)11

6. Given num1 = 0, num2 = 1 the statement (num1 < num2) && (num1 > num2) evaluates to
A)true B)false C)1 D)0

7.Given num1 = 0, num2 = 1 the statement (num1 < num2) || (num1 > num2) evaluates to
A)true B)false C)1 D)0

8. Given num1 = 0, num2 = 1 the statement !(num1 > num2) evaluates to


A) true B) false C) 1 D) 0

9. Given num1 = 0, num2 = 1 the statement !(num1 < num2) evaluates to


A) true B) false C) 1 D) 0

10. The expression 19 % 4 evaluates to


A) 2 B) 4 C) 3 D) 1

11. The expression 19 / 4 evaluates to


A) 2 B) 4 C) 3 D) 1

12. The statement System.out.println("One" + 1 + 1); gives the output


A) One2 B) One1 C) 2One D) One11

13. What is the value of y after evaluating the expression given below?
y += ++y + y-- + --y; when int y = 8.
A) 32 B) 33 C) 34 D) 35

14. What is the value of x1 when x=5?


x1 = ++x - x++ + --x;
A) 4 B) 5 C) 7 D) 6
15. What is the result stored in x, after evaluating the following expression? int x = 5;
x = x++ * 2 + 3 * --x;
A) 25 B) 24 C) 23 D) 26

16. What will be the result stored in X after evaluating the following expression? int X = 4;
X += (X++) + (++X) + X;
A) 19 B) 20 C) 21 D) 22

17. Write the Output:


char ch= 'A';
int m=ch;
m=m+5;
System.out.println(m + " " + ch);
A) 70A B) 71 C) A70 D) 72 A

18. What is the output of the following program snippet?


char x = ‘a’; int m;
m = (x == ‘a’) ? ‘A’ : ‘a’;
System.out.println(“m=”+m);
A) m=65 B) m=97 C) m=’a’ D) m=’A’

19. What will be the output of the following code?


int k=5, j=9;
k += k++ - ++j + k;
System.out.println(“k=”+k);
System.out.println(“j=”+j);
A) k=7 j= 11 B) k=6 j= 11 C) k=7 j= 10 D) k=6 j= 10

20. What will be the output of the following code?


int a = 5;
a++;
a -= (a--) - (--a);
System.out.println(a);
A) 3 B) 4 C) 5 D) 6

21. An operator taking three operands for its operation is:


A. A unary operator B. A binary operator C. A ternary operator D. There is no such operator

22. What is the output of the code snippet?


int x = 'a';
System.out.println(x);
A. ‘a’ B. 97 C. null D. x
23. The expression 8 % 2 * 3 evaluates to:
A. 2 B. 12 C. 0 D. 48

24. The value of b evaluates to:


boolean b = (true == false) ? true : false;
A. true B. false C. null D. Runtime error

25. What is the output of the code snippet?


char c = (char)65;
System.out.println(c);
A. 65 B. A C. null D. c

Part 5 - Inputs in Java

1.Which of the following are valid comments?


1./* comment */ 2./* comment 3.// comment 4.*/ comment */

A)1 only B)3 only C)1 and 3 D)1, 3 and 4


2. Name the type of error that occurs for the following statement:
System.out.println(Math.sqrt(36-45));
A)Syntax error B)Runtime error C)Logical error D)No error

3. Name the type of error that occurs for the following statement:
int a;b;c;
A) Syntax error B)Runtime error C)Logical error D)No error

4.Pick the statement that will include all the classes present in java.util package into your program:
A) include java.util B) java.util C)package java.util D) import java.util.*

5. Name the type of error that occurs for the following scenario:
Division by a variable that contains a value zero.
A)Syntax error B)Runtime error C)Logical error D)No error

6. Name the type of error that occurs for the following scenario:
Multiplication operator used when the operation should be division.
A) Syntax error B) Runtime error C) Logical error D) No error

7. Name the type of error that occurs for the following scenario:
Missing semicolon at the end of a statement.
A) Syntax error B) Runtime error C) Logical error D) No error

8. Which option completes the following statement:


Scanner sc = ------- Scanner (------);
A) new and System.in B) old and System.in C) new and System.out D) new and java.in

9. Name the package that contains Scanner class.


A) java.io B) java.scanner C) scanner.io D) java.util

10. Which of the following statement we must write to import just the Scanner class from the java.util package
A) import java.util.*
B) import package java.util.Scanner
C) include java.util.Scanner
D) import java.util.Scanner

11. Which of the following is/are an invalid comment(s)?


1. /* comment */
2. /** comment **/
3. // comment
4. */ comment */
A) 2 only B) 4 only C) 2 and 4 D) 2, 3 and 4

12. Name the method of Scanner class that is used to input an integer data from the standard input device
A) NextInt() B) nextInteger() C) nextNumber() D) nextInt()

13. Name the keyword used to call a package in the program


A) package B) include C) call D) import

14. Name the input source that a Scanner object uses to accept data from the standard input device
A) System.in B) System.input C) Scanner.in D) Java.input

15. The following code snipped will result in:


int i;
i++;
A) Syntax error B) Runtime error C) Logical error D) No error

16. Pick the invalid method that is not in the Scanner class:
A) nextInt() B) next() C) nextNumber() D) nextLong()

17. Pick the default delimiter used in the Scanner class:


A) Semicolon B) Comma C) Whitespace D) There is no default delimiter
18. The pacakage that contains methods to display date and time is:
A) Java.date B)java.lang C) java.io D) java.util

19. Which statement is true?


A) The next() method is used to read the next complete token
B) The nextLine() method is used to read a complete line of text
C) The next().charAt(0) returns the first character
D) All of the above

20. Name the method of Scanner class that checks if the Scanner has another token in its input:
A) hasNext() B) nextToken() C) getNext() D) hasNextToken()

Part – 6 Mathematical Library Methods


I. Objective Type Questions:
1.What is the output of the following Math function?
Math.floor(-7.7)
A)8.0 B)7.0 C)-7.0 D)-8.0

2.What is the output of the following Math function?


Math.ceil(5.4) + Math.ceil(4.5)
A)9.0 B)10.0 C)11.0 D)12.0

3.What is the output of the following Math function?

Math.ceil(-5.4) + Math.ceil(-4.5)
A)-9.0 B)-10.0 C)9.0 D)10.0

4.What is the output of the following Math function?


Math.abs(Math.min(-2.84, -6.54))
A)-2.84 B)-6.54 C)2.84 D)6.54

5.What is the output of the following Math function?


Math.sqrt(Math.floor(25.9))
A)25.0 B)5.0 C)26.0 D)6.0

6.What is the output of the following Math function?


Math.ceil(4.5 + 4.4)
A) 8.0 B) 9.0 C) 10.0 D) Runtime error

7. What is the output of the following expression?


Math.round(Math.abs(-0.5))
A) 1 B) -1 C) 0 D) Runtime error

8. Which package includes the Math class?


A) java.math B) java.util C) java.lang ( java.lang.Math) D) Java.io

9. Which package is imported by default in a Java program?


A) Java.math B) Java.util C) Java.lang D) Java.io

10. Which statement is correct? Math.random() returns a:


A) double value greater than or equal to 0.0 and less than 1.0
B) int value greater than or equal to 0 and less than 1
C) double value greater than or equal to 0.0 and less than or equal to 1.0
D) int value greater than or equal to 0 and less than or equal to 1

11. What will be the output of Math.cbrt(-64)?


A) -4.0 B) 4.0 C) 0.0 D) Runtime error – we cannot use a negative number

12. What will be the output of Math.pow(-1, 0)?


A) -1.0 B) 1.0 C) 0.0 D) Runtime error – we cannot use a negative number
13. Which of the following is a method to find the cube root of a number?
A) cubeRoot(x) B) Cbrt(x) C) Math.cubeRoot(x) D) Math.cbrt(x)

14. Which of the following is true for Math.round() method?


A) If the argument type is double, the return type is long.
B) If the argument type is float, the return type is int.
C) The method returns the closest int or long.
D) All of the above are true.

15. What will be the output of Math.abs(-3.1)?


A) -3.1 B) 3.0 C) 3.1 D) -3.0

Conditional Constructs in Java


Objective Type Questions:

1.What is the value of variable x?


int a = 99, b= 76;
boolean x = (a > b) ? true : false;
A) true B)false C)99 D)76

2.What is the value of variable x?


int a = 99, b= 76;
int x = (a < b) ? a : b;
A)true B)false C)99 D)76

3.An if-else statement can be represented by which operator in Java?


A)if B)? C)! D)?:

4.Which option is the correct rewrite of the following statement?


if (salary > 10000)
bonus = salary * 0.1;
else
bonus = 0;
A)bonus = (salary > 10000) ? salary * 0.1 : 0;
B)salary = (salary > 10000) ? salary * 0.1 : 0;
C)salary = (bonus > 10000) ? salary * 0.1 : 0;
D)bonus = (bonus > 10000) ? salary * 0.1 : 0;

5.Given the following code snippet:


int x = 1, y = 1;
if (n > 0)
{
x++;
--y;
}
What will be the value of x and y when n = 0?
A) x = 2, y = 0 B) x = 0, y = 2 C) x = 1, y = 0 D) x = 1, y = 1

6. Given the following code snippet:


int x = 1, y = 1;
if (n > 0)
{
x++;
--y;
}
What will be the value of x and y when n = 1?
A) x = 2, y = 0 B) x = 0, y = 2 C) x = 1, y = 0 D) x = 1, y = 1
7. What type of type casting is shown in the following statements?
1) char c = (char) 120;
2) int x = 't';

A) Explicit in both 1) and 2) B) Implicit in both 1) and 2) C) Explicit in 1) and Implicit in 2)


D) Implicit in 1) and Explicit in 2)

8. Which statement(s) is/are true for the given code snippet?


if (x = y);
x=0
else
x++
A) The assignment operator is used instead of the equality operator B) There should be no semicolon after if (x = y);
C) Semicolon is required after x = 0 and x++ D) All of the above are true

9. Given the following code snippet.


String grade = (marks >= 90) ? "A": (marks > 80) ? "B" : "C";
What will be the value of grade when marks = 81?
A) A B) B C) C D) Runtime error

10. Given the following code snippet.


int p = 3, q = 2, r = 1;
switch(n)
{
case 1: p++;
case 2: q++;
case 3: r++;
}
What will be the value of p, q and r when n = 2?
A) p = 3, q = 3, r = 2 B) p = 3, q = 3, r = 3 C) p = 3, q = 2, r = 2 D) p = 3, q = 2, r = 1

11. Given the following code snippet.


int p = 3, q = 2, r = 1;
switch(n)
{
case 1: p++;
case 2: q++;
case 3: r++;
}
What will be the value of p, q and r when n = 0?
A) p = 3, q = 3, r = 2 B) p = 3, q = 3, r = 3 C) p = 3, q = 2, r = 2 D) p = 3, q = 2, r = 1

12. Which statement will produce the absolute value of variable x?


A) x = x < 0 ? -x : -x; B) x = x < 0 ? x : -x; C) x = x > 0 ? -x : x; D) x = x < 0 ? -x : x;

13. Which keyword is optional in the switch statement?


A) switch B) case C) default D) None of the above

14. Which keyword is mandatory in the switch statement?


A) break B) case C) default D) return

15. if ((a < b) && (a < c)), then which of the following statement is true?
A) a is the smallest number B) b is the smallest number
C) c is the smallest number D) b is the largest number
Iterative Constructs
I. Objective Type Questions:

1.How many times the following loop will execute?

int counter = 1;
do
{
System.out.println(counter);
}
while (++counter < 5);
A)4 B)5 C)6 D)Infinite time

2.How many times the following loop will execute?


int counter = 1;
do
{
System.out.println(counter);
}
while (counter++ < 5);
A)4 B)5 C)6 D)Infinite time

3.How many times the following loop will execute?


int counter = 6;
do
{
System.out.println(counter);
}
while (counter++ < 5);
A)1 B)2 C)5 D)6

4.How many times the following loop will execute?


for (int i = 5; i > 10; i++)
System.out.println(i);
A) 0 B) 1 C) 5 D) Infinite time

5. What will be the final value of x and y at the end of code snippet?
int x = 2, y = 10;
for (int i = 1; i < 5; i++)
x++; y++;
A) x = 6, y = 14 B) x = 6, y = 11 C) x = 5, y = 11 D) x = 5, y = 14

6. Given the following code snippet:


int j = 1, k = 2;
while (++k < 5)
j *= k;
Which of the following statement is true?
A) The output will be 1 and the loop will execute 0 time B) The output will be 3 and the loop will execute 1 time
C) The output will be 12 and the loop will execute 2 times D) The output will be 60 and the loop will execute 3 times

7. How many times the following loop will execute?


for (int i = 1; i <= 6; i++)
for (int j = 1; j <=6; j++)
System.out.println("Loop");
A) 6 B) 25 C) 36 D) 49

8. How many times the following code snipped will display “Loop”?
for (int i = 1; i <= 3; i++)
for (int j = 1; j <=3; j++);
System.out.println("Loop");
A) 1 B) 3 C) 9 D) 10
9. Which of the following statement is correct?
A) A for loop always executes once B) A while loop always executes once
C) A do-while loop always executes once D) All loops always execute once

10. A loop that never terminates is:


A) A null loop B) A for loop C) An empty loop D) An infinite loop

11. Which of the following statement is correct?


A) A while loop is entry-controlled whereas do-while is exit-controlled
B) A do-while loop is entry-controlled whereas while is exit-controlled
C) Both while and do-while are exit-controlled
D) Both while and do-while are entry-controlled

12. Which of the following statement is not true?


A) To execute a do-while loop the condition must be true when entering the loop
B) To execute a while loop the condition must be true when entering the loop
C) To execute a for loop the condition must be true when entering the loop
D) All are true

13. Which of the following for loops will cause the body of the loop to be executed 5 times?
A) for (int i = 5; i > 1; i-- ) B) for (int i = 1; i < 5; i++ )
C) for (int i = 0; i < 5; i++ ) D) for (int i = 0; i <= 5; i++ )

14. Which of the following is not a jump statement in Java?


A) continue B) break C) jump D) return

15. Which of the following is an empty loop?


A) do {i++;} while (i < 5); B) while (i < 5) i++; C) for (i = 0; i < 5; i++); D) None of the above

Class as the Basis of all Computation


I.Objective Type Questions:

1.Which operator instantiates a class by allocating memory for a new object?


A)allocate B)memory C)new D)create

2.You can assess the member variables using:


A)new operator B)dot operator C)increment operator D)ternary operator

3.Which of the following is a primitive data type?


A)byte B)short C)boolean D)All of the above

4.In a method call, the composite data types are passed:


A)By value only B)By reference only C)Both by value and reference D)Cannot be passed

5.Which of the following is a composite data type?


A)class B)arrays C)String D)All of the above

6.When composite data is copied to a variable:


A)the variable gets its own unique copy of the data, stored separately in memory
B) only a reference to the data is stored in the variable.
C) nothing is stored in the variable.
D) cannot copy composite data to a variable

7. A class contains:
A) member variables only B) member methods only C) void methods only
D) member variables and member methods
8. When two variables containing composite data are compared, they are compared:
A) By value only B) By reference only
C) Both by value and reference D) Cannot be compared

9. A class created by a programmer is:


A) User-defined data type B) Primitive data type C) System defined data type
D) A programmer cannot create classes in Java

10. Choose the method that converts a string to a primitive integer data type:
A) Integer.parse() B) Integer.toString() C) Parse.IntegerNumber() D) Integer.parseInt()

11. Given the following statements:


1) An integer variable contains the value itself.
2) An object variable contains the address where the object is stored.

A) Only 1) is true B) Only 2) is true C) Both 1) and 2) are true D) 1) is true but 2) is false

12. Choose the correct statement:


A) Primitive data types are predefined by the language
B) Composite data types are constructed using primitive data types
C) User defined data types are created by user to perform specific tasks
D) All of the above statements are true

13. Choose the method that converts a string to a primitive float data type:
A) Float.parseFloat() B) Float.convert()
C) Parse.floatNumber() D) Float.parse()

14. Choose the correct answer in reference to the following statement:


Employee staff = new Employee();
A) It creates an object named new of class type Employee
B) It creates an object named Employee of class type staff
C) It creates an object new Employee of class type staff
D) It creates an object named staff of class type Employee

15. The keyword that distinguishes between instance variable and class variable is:
A) static B) final C) private D) protected

User Defined Methods


I.Objective Type Questions:
1.Which of the following is not an advantage of methods or functions in Java?
A)Methods boost code reusability
B)Methods help divide complex programs into manageable code blocks
C)Methods help in improving code readability
D)You wouldn’t need explicit type casting if you use methods

2.Which of the following is a false statement about methods?


A)List of parameters are optional in Methods
B)Method body doesn’t need to be enclosed in a Curley bracket if it contains a single line of code.
C)Methods Signature is part of the Method Prototype
D)The type of data returned by method can be any valid Java data type
3.Which of the following is a false statement about methods?
A)The method calling statement must provide all the parameter values
B)The type and number of parameters in the invoke statement must match with those of the method prototype.
C)The order of parameters in the invoke statement must match with that of the method prototype.
D)Each method must contain at least one return statement

4.Which of the following parameter passing technique is supported in Java?


A)Pass by value only B)Pass by reference only
C)Both pass by value and reference D)None of the above

5. Given the following statements:


1)During call by value, any change in the formal parameter is not reflected to the actualparameter
2)During call by value, any change in the formal parameter is reflected to the actual parameter
3)During call by reference, any change in the formal parameter is not reflected to the actualparameter
4)During call by reference, any change in the formal parameter is reflected to the actualparameter

Pick the right answer.


A)Only 1) is true B)Only 4) is true C)Both 1) and 4) are true D) Both 2) and 4) are true

6. Given the following statements:


1) A Pure Method does not change the original state of an object
2) A Pure Method does change the original state of an object
3) An Impure Method does not change the original state of an object
4) An Impure Method does change the original state of an object

Pick the right answer.


A) Only 1) is true B) Only 4) is true C) Both 2) and 3) are true D) Both 1) and 4) are true

7. How is a primitive data type passed in Java?


A) By value only B) By reference only
C) Both by value and reference D) Java doesn’t allow passing primitive data types

8. Choose the correct option that defines a prototype of the method “sum” that takes an integer variable x
as its argument and returns a value of float data type.
A) int sum(float x) B) void float sum(int x) C) float sum(int x) D) void sum(int x)

9. How is a reference data type passed in Java?


A) By value only B) By reference only C) Both by value and reference
D) Java doesn’t allow passing reference data types

10. Choose the correct option that defines a prototype of the method “check” which receives a character ch and
an integer n and returns true or false value.
A) boolean check(char ch, int n) B) void boolean check(char ch, int n)
C) boolean check(int ch, int n) D) boolean check(char ch, char n)

11. Choose the correct option that defines a prototype of the method PosChar that takes a string argument and
a character argument and returns an integer value.
A) int PosChar(String stg, character ch) B) int PosChar(String stg, char ch)
C) void int PosChar(String stg, char ch)
D) int void PosChar(String stg, char ch)

12. Choose the correct option that defines a prototype of the method “search” which receives a sentence sentnc and a word
wrd and returns 1 or 0.
A) int search(String sentnc, String wrd) B) int search(Sentence sentnc, Word wrd)
C) void search(String sentnc, String wrd) D) void int search(String sentnc, String wrd)

13. Method overloading in Java is implemented by:


A) Polymorphism B) Polymethods C) Prototyping D) Packages

14. A method that doesn’t return a value has a return type of:
A) null B) void C) int D) new
15. The parameters that appear in the method call statement are:
A) call parameters B) void parameters C) actual parameters D) formal parameters

Constructors
I.Objective Type Questions:
1.A class having multiple definitions of constructors is termed as Constructor ----
A)Abstraction B)Overlaying C)Overloading D)Multiclass

2.If a class has no constructor, then:


A)A Syntax error occurs B)A Runtime error occurs
C)The program will be unable to call the main method D)The compiler automatically generates one

3.Name the keyword that stores the address of currently-calling object:


A)this B)that C)current D)void

4.The constructor has a return type of:


A)int B)void C)no return type D)String

5.A member method with the same name as class:


A)is not allowed in Java B)is called a constructor C)is only allowed in a sub class
D)is only allowed in a super class

6.Name the keyword that refers to the current object:


A)void B)main C)this D)instance

7.A constructor is invoked:


A)at the time of program compilation B)at the time of object creation
C)at the time of object comparison D)after all objects in a class have been initialised

8. It is allowed to have a member method with a name same as that of the class when:
A) it is a constructor B) the class is a super class C) the class is a sub class D) the class has void methods

9. Given a class named Rectangle, which is/are valid constructor names of the class:
A) public Rectangle () B) public Rectangle (int length)
C) public Rectangle (int length, int width) D) All of the above are valid constructors

10. Given a class named Student, which is a valid constructor name of the class:
A) public Student() B) public void Student() C) public student() D) public void student()

11. A constructor can be invoked only via the:


A) increment operator B) new operator C) this operator D) ternary operator

12. Given a class named Cuboid, which statement invokes the default constructor:
A) Cuboid cuboid = new Cuboid(); B) Cuboid cuboid = new Cuboid(10);
C) Cuboid cuboid = new Cuboid(10, 20); D) Cuboid cuboid = new Cuboid(10, 20, 30);

13. Name the keyword that is used to resolve the conflict between parameter and instance variables:
A) reference B) new C) this D) void

14. Predict the output of the following code:


public class TestFlag
{
private boolean flag;
public static void main(String args[])
{
TestFlag objTest = new TestFlag();
System.out.println(objTest.flag);
}
}
A) null B) true C) false D) Runtime error as variable flag is not initialised
15. Predict the output of the following code:

public class TestValue


{
private int value;
public static void main(String args[])
{
TestValue objValue = new TestValue();
System.out.println(objValue.value);
}
}
A) null B) 0 C) Syntax error as variable value is not initialised
D) Runtime error as variable value is not initialised

1. What is this keyword ?

Ans. this keyword is used to represent current object on which a function is called.

There may be more than one objects of a single class and each object may invoke the
same function of the class. For a function to differentiate its working for both objects, this
keyword is required. This refers to the current object that invoked the function.

a) Name the keyword is used to resolve the conflict between method parameter and instance variables/fields.
b) Ans : Keyword this is used.

class This_example
{
int length, breadth;
This_example ()
{
length = 100;
breadth = 200; length breadth
}
void rectangle(int l, int b) 100 200
{
this.length=l;
this.breadth=b;
} this.length this.breadth
void display( )
{ 5 10
System.out.println(length);
System.out.println(breadth); Output
}
void display( ) 100
{ 200
System.out.println(this.length); 5
System.out.println(this.breadth);
} 10
public static void main ( )
{
This_example ob = new Thisexample_ex ( );
ob.display();
This_example ob1 = new This_example ( );
ob1.rectangle(5, 10);
ob1.display1( );
}
}
WRITE THE OUTPUT OF THE PROGRAM.

import java.util.*;
class This_exam
{
int length, breadth;
This_exam()
{
length = 100;
breadth = 200;
}
void rectangle(int l, int b)
{
this.length=l;
this.breadth=b;
}
void display( )
{
System.out.println(length);
System.out.println(breadth);
System.out.println(length * breadth);
}
void display1( )
{
System.out.println(this.length);
System.out.println(this.breadth);
System.out.println(this.length * this.breadth);
System.out.println("this.length " + this.length);
System.out.println("breadth " + breadth);
System.out.println("this.length * this.length " + this.length * length);
System.out.println("\n\nlength * this.breadth " + length * this.breadth);
}
public static void main (String args[])
{
This_exam ob = new This_exam( );
ob.display();
This_exam ob1 = new This_exam( );
ob1.rectangle(5, 10);
ob1.display1( );
}
}

Take print out and study. Any doubts u can call me and clarify .

You might also like