0% found this document useful (0 votes)
702 views14 pages

Choose The Correct Answers: (C) Inheritance

Uploaded by

3D GMR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
702 views14 pages

Choose The Correct Answers: (C) Inheritance

Uploaded by

3D GMR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

1.

Choose the correct answers

(i) Name the feature of Java depicted in the following picture.

(a) Data Abstraction (b) Encapsulation (c) Inheritance (d) Polymorphism


(ii) The method of Scanner class to accept a 64-bit floating point number is:
(a) nextInt() (b nextLong() (c) nextFloat() (d) nextDouble()
(iii) Classes, interfaces, methods, packages and variables are together called:
(a) Keywords (b) Identifiers (c) User defined words (d) None of the these
(iv) The keyword that makes a variable constant is:
(a) int (b) switch (c) final (d) All of these
(v) A loop programmed within another loop is known as:
(a) Null loop (b) Nested loop (c) Void body loop (d) All of these
(vi) Identify the valid keyword:
(a) For (b) INTEGER (c) case (d) elseif
(vii) Predict the output:
System.out.println (‘B’
+2);
(a) 100 (b) B2 (c) 1002 (d) 68
(viii) The feature of OOP implemented by Method overloading is:
(a) Inheritance (b) Polymorphism (c) Encapsulation (d) Data abstraction

(ix) Name the package that contains ‘String’ class.


(a) java.lang (b) java.io (c) java.awt (d) java.applet
(x) Identify the type of error in the following
statement:System.out.println(7 / 0.0);
(a) Syntax (b) Logical (c) Runtime (d) No error
(xi) What will be the data type of variable s in the following statement ?
s = “Major” . startsWith(“M”);
(a) int (b) char (c) String (d) boolean
(xii) The number of bytes occupied by an array of double type with 5 elements
is:(a) 10 (b) 20 (c) 40 (d) 50
(xiii) Semicolon (;) in Java programming is a kind of:
(a) Operator (b) Separator (c) Special Symbol (d) Literal
(xiv) Predict the output:
System.out.println(Character.toLowerCase(‘E’
));
(a) e (b) 69E (c) false (d) None of these
Page 1 of 5
(xv)Assertion (A): To call abs() method no object or class name is
required.Reason (R): All methods of Math class are class methods.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct
explanationof Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation
ofAssertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false

(xvi) Go through the following text and choose the correct answer:
Selection statements help in selecting one alternative out of more than one options. They are also
called decision-making statements as the computer needs to take a decision while executing
these statements as per the conditions provided. The output of the program depends upon the
statement selected by the computer based on the validity of the condition.

Selection statements are used to:


(a) check conditions (b) take decision
(c) select an alternative of many statements (d) All of these

(xvii) Assertion (A): An array variable is also known as subscripted variable.


Reason (R): In arrays, every element is represented with the help of its individual index.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation
of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation
ofAssertion(A)
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is false and Reason (R) is true
(xviii) The value of variable r in the following statement will
be:double r = Math.rint (28.5);
(a) 28 (b) 28.0 (c) 29 (d) 29.0
(xix) The variable to access the 10th element of an array a[]
is:(a) a[9] (b) a[10] (c) a[11] (d) a[0]
(xx)boolean b[ ] = {true,
false}; System.out.println
(b[1] * 2);
What will be the output of the above code fragment ?
(a) 2 (b) 0 (c) true * false (d) Syntax error

Page 2 of 5
[20]
2. Choose the correct answers
(i)

Name the feature of java depicted in the above picture.


(a) Encapsulation
(b) Inheritance
(c) Abstraction
(d) Polymorphism

(ii) How many bytes does float and double requires?


(a) Float-->2,Double-->4
(b) Float-->4,Double-->8
(c) Float-->8,Double-->16
(d) None of these

(iii) Which of the following statement is TRUE?


(a) / is the division operator whereas % is the modulus (remainder) operator.
(b) % is the division operator whereas / is the modulus (remainder) operator.
(c) / is the logical operator whereas % is the relational operator.
(d) None of these
(iv) Static variables belong to the:
(a) Class
(b) Library
(c) Object
(d) Identifiers

(v) What is the extension of a byte code file?


(a) .java
(b) .javac
(c) .class
(d) .doc

(vi) Reference types are .................


(a) Arrays
Page 3 of 5
(b) Classes
(c) Interfaces
(d) all of the above

(vii) What is the final value stored in variable x? double x =


Math.ceil(Math.abs(-7.3));
(a) 7.0
(b) 8.0
(c) 6.0
(d) 9.0
(viii) Assertion(A): The base class and derived class are the terms used in abstraction.
Reason(R): the concept of extending a class to obtain another class is called inheritance.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct
explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct
explanation of Assertion(A)
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is false and Reason (R) is true

(ix) What does the statement “int a=20” signifies?


(a) It is a declaration statement where “a” is a variable holding 20 as its value.
(b) The variable “a” is of type integer
(c) All of these
(d) None of these

(x) int f= 10,m=9;


String e=(m%f==9)?"YES":"NO";
System.out.print(e);
(a) YES
(b) NO
(c) YESNO
(d) NOYES

(xi) Which of the following data types can have only one value at a time?
(a) Primitive
(b) Reference
(c) Abstract
(d) Import

(xii) Which of the following return statement is wrong?


(a) return 0;
(b) return (s);

Page 4 of 5
(c) return(s,p);
(d) return (4);

(xiii) What makes the two or more functions having the same name different?
(a) Number of arguments
(b) Type of arguments
(c) a&b
(d) All of the above

(xiv) Which of the following is a correct prototype of a function check which receives a
character ch and integer n and returns true or false?
(a) pubic int check( char ch,int n);
(b) public boolean chk(char ch, int n);
(c) public boolean check(char ch, integer n);
(d) public boolean check( char ch, int n);

(xv) Which type of the function increases the value of its return type by 1, each time the
function is called:
(a) Non-static function
(b) Static function
(c) Impure function
(d) None of the above

(xvi) The keyword which refers to the current object is:


(a) new
(b) private
(c) void
(d) this

(xvii) Autoboxing is:


(a) Converting the primitive data type from one type to another
(b) Converting wrapper class object.to primitive data type
(c) Converting the primitive data types into its corresponding wrapper class object.
(d) None of the above

(xviii) The statement that converts the string object s=”400” to integer “s_int” is
................
(a) s_int=Integer.parse(s);
(b) s_int=Integer.Int(s);
(c) s_int=Integer.parseInt(s);
(d) s_int=integer.parseInt(s);

Page 5 of 5
(xix) The second last element of an array of size 100, has index:
(a) 97
(b) 99
(c) 98
(d) 100

(xx) Given an array ar[]={10,20,30,40,50}, the statement ar[3]-1 will return:


(a) 40
(b) 30
(c) 39
(d) 29
3. Choose the correct answers

(i) Name the feature of java depicted in the below picture

(a) Encapsulation
(b) Inheritance
(c) Abstraction
(d) Polymorphism
(ii) How many bytes of memory will the following array use? double b[ ] = new double[6];
(a) 48 bytes
(b) 24 bytes
(c) 48 bits
(d) 24 bits
(iii) Give the output of the following statements:
String x[ ] = {"Apple", "Blueberry", "Grapefruit", "Tomato", "Watermelon"};
System.out.println(x[3].length());
(a) 10
(b) 5
(c) 6
(d) 9
Page 6 of 5
(iv) The output of Math.round(6.6) + Math.ceil(3.4) is:

(a) 9.0
(b) 11.0
(c) 10.0
(d) 11
(v) Which of the following is a valid Integer constant:
1. 4
2. 4.0
3. 4.3f
4. “four”
(a) Only 1
(b) 1 and 4
(c) 2 and 4
(d) 1 and 2
(vi) The _________ are the words which have special meaning
(a) Keywords (b) Identifier
(c) Methods
(d) Package
(vii) What is true about do while looping statement?
(a) do while statement executes the code of a loop at least once
(b) do while statement does not get execute if condition is not matched in the first iteration
(c) do while statement checks the condition at the beginning of the loop
(d) do while statement executes the code more than once always

(viii) What is the return type of a method that does not return any value?
(a) int
(b) void
(c) float
(d) null
(ix) Name the search algorithm which compares the sought key value with the key value of middle
element of the array at each stage.
(a) Bubble sort
(b) Linear search
(c) Binary search
(d) Selection sort
Observe the following code snippet and answer the questions (x) and (xi) switch (opn)
{ case 'a':
Page 7 of 5
System.out.println("Red"); break; case
'b':
System.out.println("Orange"); case 'c':
System.out.print("Blue"); break; default:
System.out.println("White");
}
(x) What will the output if opn= ‘A’?
(a) Red
(b) Orange
Blue
(c) White
(d) Blue
(xi) What will the code print if opn= ‘b’?
(a) Orange
Blue
(b) OrangeBlue
(c) Orange
(d) Blue
(xii) Which of the following statement contains an error?
(a) int a[]= int[10];
(b) float d[]={1,2,3};
(c) int a[]= {1,2}; int b[]; b=a;
(d) All the above
(xiii) How many values can return statement take back to the caller method?
(a) 0
(b) 1
(c) 2
(d) Many
(xiv) What will be the output of the following program?
int count = 1; while (count <= 15) {
System.out.println(count % 2 == 1 ? "***" : "+++++"); ++count;
} // end while
(a) 15 times ***
(b) 15 times +++++
(c) 8 times *** , 7 times +++++ (d) both will print only once

Page 8 of 5
(xv) Consider the following class: class Test { public static void swap(int i, int j) {
int temp=i;
i = j; j = temp;
}
public static void main(String[] args) { int i=10,j=20;
swap(i, j);
System.out.println("i = " + i + ", j = " + j);
}}

(a) i=10,j=20
(b) i=20,j=10
(c) i=10,j=10
(d) i=20,j=20
(xvi) Which of these jump statements can skip processing the remainder of the code in its body for a
particular iteration?
(a) break
(b) return
(c) System.exit(0)
(d) continue
(xvii) Assertion(A): Object is a instance of a class
Reason(R): A class describes the characteristics and behaviour that which is imbibed in its object.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of
Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a
correct explanation of Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false (xviii) Read the following text, and choose the
correct answer:
A two-dimensional array, also known as a 2D array, is a collection of data elements arranged in a
grid-like structure with rows and columns. Each element in the array is referred to as a cell and
can be accessed by its row and column indices/indexes. A 3X4 2D array typically stores 4
elements in each of the 3 rows.
How many elements will be stored in a 2D array of size 5X3
(a) 8 elements
(b) 20 elements
(c) 15 elements
(d) 35 elements

Page 9 of 5
(xix) Assertion(A): do while loop is executed atleast once even if it’s condition is false.
Reason(R): A do while loop tests condition before entering the loop body.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of
Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false
(xx) Which of the following is correct way to initialize a 3X2 two-dimensional array?
(a) int dim[ ][ ] = {{1,2,3},{8,7,6}};
(b) int dim[ ][ ] = new int{{1,2,3},{8,7,6}};
(c) int dim[ ][ ] = {{1,2,3,8,7,6}};
(d) int dim[ ][ ] = {{1,2},{5,4},{8,7}};

4. Choose the correct answers


[20]
(i) Name the feature of Java depicted in the following picture.

(a) abstraction (b) encapsulation (c)inheritance (d)polymorphism


(i) In Java a constructor with no parameter is called a
(a)Default constructor (b)user defined constructor
(c)custom constructor (d)static constructor
(ii) Private function is accessible to......
(a)Own class only (b)sub class and class in the same package (c)subclass
(d)none of these.
(iii) Function prototype means
(a)Return value of a function (b)Name of a function (c)Return type of a
function (d)Return type, name and argument of a function.
(iv) Which of the following represent the constructor of the ABC class
(a)ABC() (b)ABC (c)ABCconstructor (d)Constructor ABC ()
(v) What is the return type of indexOf() function of string class?
(a)char (b) String (c)boolean (d)int
(vi) The ability of a method or object to take on multiple forms is called.
(a) abstraction (b) encapsulation (c)inheritance (d)polymorphism

Page 10 of
5
(vii) Which of the following is a keyword?
(a) token (b) continue (c) constant (d) all of these
(viii) Name the method used to convert String value into int?
(a) ParseInt() (b) parseInt() (c) parseInteger (d) none of
these
(ix) The ……… allows a class to use property of another class.
(a) Encapsulation (b) Abstraction (c) inheritance (d) None of these
(x) The ……… operator is used to access method of a class.
(a) Object (b) new (c) (.)dot (d) import
(xi) The statement System.out.println(1+2+“four ”+2+3); gives the output………
(a)3 four 5 (b)3 four 23 (c) 12 four 23 (d) error
(xii) x + = x++ + --x + --x + x; [ x = 5 ]
(a) 23 (b) 20 (c) 18 (d) none of these
(xiii) Math.pow(Math.ceil(4.22), Math.cbrt(8));
(a) 16 (b) 25 (c) 25.0 (d)16.0
(xiv) Consider the following String array and give the output:
String arr[ ]={"Java", "PHP", "Python", ".Net", "HTML"};
System.out.print( arr[2].charAt(2)+” “+arr[3].indexOf(‘N’));
(a) h -1 (b) H 1 (c) t 1 (d) Runtime Error
(xv) Predict the output of the following statement:
String wd[ ] = {"INDIA", "USA", "NEPAL", "GERMANY", "MEXICO"};
System.out.println(wd[2].substring(0,3) + wd[4].substring(4));
(a) USANY (b) MEXPAL (c) NEPCO (d) INDNY
(xvi) The return data type of Integer.parseInt( ) method is ________ .
(a) String (b) int (c) void (d) Integer
(xvii) Which of the following is not a type of inheritance?
(a) multiple (b) double (c) hybrid (d) single
(xviii) Corresponding wrapper class of the char data type is?
(a) String (b) Character (c) Char (d) CHARACTER
(xix) The process to change one data type value to another data type is known as
(a)Declaration (b)Type conversion (c) Converting data type (d)Initialising data type

5. Choose the correct answers


(i) Name the feature of Java depicted in the following picture.

(a) a) Encapsulation (b) Data Abstraction (c) Polymorphism (d) Inheritance


(ii) The code that operates on the data of an object is termed as:
(a) a) Member function (b) Class (c) Object program (d) Message
(b) (iii) Which of the following is not a token ?
(a) Keyword (b) Identifier (c) Procedure (d) Operator

Page 11 of
5
(iv) Which operator among the following is unary ?
(a) ! (b) ++ (c) -- (d) All of these
(v) a ____________ method needs to be called with the help of object
(a) void (b) class (c) static (d) nonstatic
(vi) *= is an example of _____ operator:
(a) logical (b) ternary (c) shorthand (d) assignment
(vii) What will be the result produced by the following statement ?
Math.ceil(8.4) + Math.pow(2,2);
(a) -13 (b) -9.45 (c) -7.75 (d) 13.0
(viii) Identify the error: System.out.println(max(4, 5));
(a) Syntax (b) Logical (c) Runtime (d) No error
Page 1 of 5

(ix) Name the package that contains ‘Integer’ class.


(a) java.lang (b) java.awt (c) java.io (d) java.applet
(x) Which of the following is an invalid literal ?
1. “763” 2. 25D 3. ‘LION’ 4. ‘\0’
(a) 1 and 2 (b) Only 2 (c) Only 3 (d) 3 and 4
(xi) Which of the following methods extracts a part of the original string?
(a) parseString() (b) getString() (c) substring() (d) extString()
(xii) The number of bytes occupied by an array of int type with 7 elements is:
(a) 56 (b) 7 (c) 14 (d) 28
(xiii) Which of the following is not a jump statement ?
(a) return (b) continue (c) break (d) None of these
(xiv) Predict the output:
System.out.println("MONARCH".substring(4).charAt(0));
(a) A (b) R (c) C (d) M

(xv) Assertion (A): When an array is initialised, its size is not specified.
Reason (R): The size of an array is equal to the number of elements in the list.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation
of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false

Go through the following text and choose the correct answer:


Non-parameterized constructor does not have any parameter list i.e. accepts no parameter. It is
also known as default constructor. A default constructor may be either implicit or explicit. Java
automatically defines an implicit constructor. It initialises the data members with their default initial
value.

A default constructor can be defined by:


(a) Java system only (b) programmers only
(c) Both a and b (d) Specific packages
Page 12 of
5
(xvi) Assertion (A): All relational operators are binary in nature.
Reason (R): Logical Not (!) operates on only one boolean value.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of
Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion(A)
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is false and Reason (R) is true

(xvii) An object that is created by explicit call to a constructor and preceded with the ‘new’ command is
termed as ______ object:
(a) Anonymous (b) Temporary (c) Explicit (d) Both a and b

(xix) int a[ ] = {2,3,4,5,6}, then a[ ].length will result in:


(a) 6 (b) 5 (c) a[5] (d) Syntax error
(xx) char ch[ ] = {'A', 'B', 'C', 'D'};
System.out.println (ch[1] + ch[3]);
What will be the output of the above code snippet ?
(a) 133 (b) 134 (c) 135 (d) 136

Page 13 of
5

You might also like