Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
208 views

Java 1

The document provides information about EXE files, Java programming concepts, and object-oriented programming concepts. Specifically: 1) EXE files provide advantages like not requiring a separate program to run and being efficient. They are also often used to transmit computer viruses and trojans. 2) In Java programming, .class files are the output of compiling Java programs. Bytecode is the result of compiling a Java file. The JDK compiles Java programs, while the JRE runs Java programs. 3) Key concepts in object-oriented programming include encapsulation, inheritance, polymorphism, and abstraction. Features like classes, objects, and interfaces support these concepts.

Uploaded by

Hami Kitta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
208 views

Java 1

The document provides information about EXE files, Java programming concepts, and object-oriented programming concepts. Specifically: 1) EXE files provide advantages like not requiring a separate program to run and being efficient. They are also often used to transmit computer viruses and trojans. 2) In Java programming, .class files are the output of compiling Java programs. Bytecode is the result of compiling a Java file. The JDK compiles Java programs, while the JRE runs Java programs. 3) Key concepts in object-oriented programming include encapsulation, inheritance, polymorphism, and abstraction. Features like classes, objects, and interfaces support these concepts.

Uploaded by

Hami Kitta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

M1

What is the advantage of EXE files?


A) Run Faster
B) Efficient
C) No separate program required to run
D) All the above
Answer[=] D

Computer Viruses and Trojans are often transmitted along with which files?
A) JPG files
B) TXT files
C) EXE files
D) .ICO files
Answer[=]
C
What is the problem with generation Executable Software (EXE files)?
A) Run only on Windows machines.
B) Linux and Unix expect a different executable format than .EXE
C) Compiler for each machine type like Linux, Unix, Windows and Processor Type needs to
be built for generating output files that can run.
D) All the above.
What is an Interpreter?
A) An interpreter converts instructions line by line
B) An Interpreter converts source code to low-level code
C) Interpreters are slow to execute
D) All the above
Answer[=]
D
What is a Compiler?
A) A Compiler converts all instructions in one go.
B) A compiler converts source code to low-level code
C) Compilers work fast
D) All the above
Answer[=]
D
What is the output of Compilation of Java Program?
A) .class file
B) .cla file
C) .jc file
D) .javax file
Answer[=]
A
Byte code is the result of?
A) Compiling a Java file
B) Compiling a Class file
C) Interpreting a Java File
D) Interpreting a Class file
Answer[=]
A
What software compiles a Java Program?
A) JRE (Java Runtime Environment)
B) JDK (Java Developer Kit)
C) JVM (Java Virtual Machine)
D) Command Prompt
Answer[=]
B
What software runs a Java program on a computer?
A) JRE (Java Runtime Environment)
B) JDK (Java Developer Kit)
C) Command Prompt
D) None of the above
Answer[=]
A
What is Portability offered by Java language?
A) Small code size easy to carry occupying less disk space
B) Generating suitable Byte Code for each machine by the Compiler
C) Ability to run the Byte on different machines producing the same behaviour and output
D) Java does not actually provide portability
Answer[=]
C
What is JIT in Java?
A) Java In Timer
B) Java In Time Thread
C) Just In Time Compiler
D) Just In Time Runnable
Answer[=]
C
Choose the correct statement about Java?
A) JIT Compiler produces Byte Code from Java file.
B) JIT Compiler takes chunks of Byte Code as input and produces Executable code on that
particular machine.
C) JIT Compiler assists the actual JAVAC compiler to compile fast
D) None of the above
Answer[=]
B
What happens in the absence of JIT Compiler in Java?
A) Byte code is produced slowly
B) Executable Code is produced slowly because of line by line Interpreting
C) Executable Code is produced without portability
D) None of the above
Answer[=]
B
What are the main Distribution types of Java Software?
A) Java SE (Java Standard Edition)
B) Java EE (Java Enterprise Edition)
C) Java ME (Java Micro Edition)
D) All the above
Answer[=]
D
What is the Java distribution type used to build Web Apps in Java?
A) Java SE
B) Java EE
C) Java ME
D) Java Embedded
Answer[=]
B
What is the Java command used to compile a java program from Command Line or
Command Prompt or CMD?
A)
>java hello.java
B)
>javac hello.java
C)
>javacomp hello.java
D)
>javacmd hello.java
Answer[=]
B
What is a Java Editor?
A) Java editor is simply an IDE like Notepad to type or edit java programs. It does not have
ability Compiling or Running java programs without installing separate Java Packages on the
PC.
B) Java editor is like Eclipse IDE that has shortcut options or buttons to compile and run java
programs without using CMD or Command Line.
C) Java IDE searches for the installed Java location for JAVAC, JAVA and JAWAH to
compile and run programs for you.
D) All the above
Answer[=]
D

Which of the following is not a Java features?

1. Dynamic
2. Architecture Neutral
3. Use of pointers
4. Object-oriented

Answer: (c) Use of pointers

M2
Which of the following language was developed as the first purely object programming
language?

1. SmallTalk
2. C++
3. Kotlin
4. Java

Answer: a. SmallTalk

Which of the following is not an OOPS concept?

1. Encapsulation
2. Polymorphism
3. Exception
4. Abstraction

Answer: c. Exception

Which feature of OOPS described the reusability of code?

1. Abstraction
2. Encapsulation
3. Polymorphism
4. Inheritance

Answer: d. Inheritance

Which of the following language supports polymorphism but not the classes?

1. C++ programming language


2. Java programming language
3. Ada programming language
4. C# programming language

Answer: c. Ada programming language

Which among the following feature is not in the general definition of OOPS?

1. Modularity
2. Efficient Code
3. Code reusability
4. Duplicate or Redundant Data

Answer: d. Duplicate or Redundant Data

A single program of OOPS contains _______ classes?

1. Only 1
2. Only 999
3. Only 100
4. Any number

Answer: d. Any number


Which operator from the following can be used to illustrate the feature of polymorphism?

1. Overloading <<
2. Overloading &&
3. Overloading | |
4. Overloading +=

Answer: a. Overloading <<

Which two features of object-oriented programming are the same?

1. Abstraction and Polymorphism features are the same


2. Inheritance and Encapsulation features are the same
3. Encapsulation and Polymorphism features are the same
4. Encapsulation and Abstraction

Answer: d. Encapsulation and Abstraction

Which of the following definition is incorrect for polymorphism?

1. Polymorphism helps in redefining the same functionality


2. Polymorphism concept is the feature of object-oriented programming (OOP)
3. It always increases the overhead of function definition
4. Ease in the readability of the program

Answer: c. It always increases the overhead of function definition

Which among the following cannot be used for the concept of polymorphism?

1. Static member function


2. Constructor Overloading
3. Member function overloading
4. Global member function

Answer: a. Static member function

Which function best describe the concept of polymorphism in programming languages?

1. Class member function


2. Virtual function
3. Inline function
4. Undefined function

Answer: b. Virtual function

Which of the following syntax is incorrect for the class definition?

1. student class{ };
2. class student{ student(int a){} };
3. class teacher{ public: teacher(int a){ } };
4. None of the mentioned

Answer: a. student class{ };

The combination of abstraction of the data and code is viewed in________.

1. Inheritance
2. Object
3. Class
4. Interfaces

Answer: b. Object

Consider the following Java program and select the right option from the given options.

class marksofstudent  

{    

     int subjectmarks;  

     public : int* fun()  

     {   

          return &subjectmarks;   

     }  

};  

main()  

{  

    marksofstudent s;  

    int *ptr = c.fun() ;  

    return 0;  

}  

1. The above program violates the feature of encapsulation


2. The above program may result in undesirable conditions
3. The above program will generate an error
4. The above program is good to go

Answer: a. The above program violates the feature of encapsulation

M3
Every statement in Java language should end with a?
A) Dot or Period
B) Comma
C) Semicolon
D) Colon
Answer[=]
C
A function in C language is similar to what in Java language?
A) Method
B) Member
C) Variable
D) None of the above
Answer[=]
A
All methods and variables in Java language are kept inside a?
A) File
B) Class or Interface
C) static method
D) main
Answer[=]
B
In standalone Java applications, which method is mandatory?
A) main method
B) show method
C) display method
D) print method
Answer[=]
A
What is the use of Access modifier "pubic" in Java language?
A) To hide the main method from misuse
B) To call the main method outside of Class or Package by JVM
C) To protect main method
D) None of the above
Answer[=]
B
Choose a Single Line Comment in Java Language below?
A)
//Some comments
B)
Some comments//
C)
/*Some comments*/
D)
*/Some comments/*
Answer[=]
A
Choose a multiline comment in Java language below?
A)
/*comments are going
cars are moving*/
B)
*/comments are going
cars are moving/*
C)
//comments are going
cars are moving//
D) None of the above
Answer[=]
A
9)
String args[] in main method are used for?
public static void main(String args[])
{
//
}
A) Passing arguments at compile time
B) Passing arguments at run time
C) Counting number of words
D) Nothing
Answer[=]
B
What is the default return type of a method in Java language?
A) void
B) int
C) short
D) None of the above
Answer[=]
D
Name of a Class, Variable, Method or an Interface in Java language is called?
A) Argument
B) Value
C) Identifier
D) None of the above
Answer[=]
C
A valid identifier in Java language may contain which characters?
A) 0-9
B) A-Z, a-z
C) $, _ (Underscore)
D) All the above
Answer[=]
D
A valid Identifier or name in Java language can start with which character?
A) a-z, A-Z
B) $, _
C) 0-9
D) A and B
Answer[=]
D
What are the valid White Spaces available in Java language?
A) Space
B) Enter
C) Tab
D) All the above
Answer[=]
D
Choose a correct version of Java Documentation Comment?
A)
/*
comments
*/
B)
/**
comments
*/
C)
/*
comments
**/
D)
/**
comments
**/
Answer[=]
B

M4
_____ is used to find and fix bugs in the Java programs.

1. JVM
2. JRE
3. JDK
4. JDB

Answer: (d) JDB

Evaluate the following Java expression, if x=3, y=5, and z=10:

++z + y - y + z + x++

1. 24
2. 23
3. 20
4. 25

Answer: (d) 25

What will be the output of the following program?

public class Test {  

public static void main(String[] args) {  

    int count = 1;  

    while (count <= 15) {  

    System.out.println(count % 2 == 1 ? "***" : "+++++");  

    ++count;  

        }      // end while  

    }       // end main   

 }  

1. 15 times ***
2. 15 times +++++
3. 8 times *** and 7 times +++++
4. Both will print only once

Answer: (c) 8 times *** and 7 times +++++

Which method of the Class.class is used to determine the name of a class represented by the class
object as a String?

1. getClass()
2. intern()
3. getName()
4. toString()

Answer: (c) getName()

Choose the wrong statement about Java programming?


A) Java supports unsigned integers
B) Java supports signed integers
C) Java supports signed char
D) None of the above
Answer[=]
A
What is a Primitive Data Type in Java?
A) Data type, which is implemented in an Object-oriented way.
B) Data Type which is implemented in a machine-dependent way
C) Data Type which is implemented in a non-object oriented way.
D) None of the above
Answer[=]
C
Which among the following is not a valid Data Type in Java?
A) long
B) bool
C) double
D) float
Answer[=]
B
Which is the data type used mostly to handle streams and buffers in Java language?
A) short
B) int
C) byte
D) float
Answer[=]
C
Choose the number range for byte data type in Java?
A) -127 to +128
B) -128 to +127
C) 0 to 256
D) 0 to 255
Answer[=]
B
What is the IEEE standard adopted to represent Floating point numbers in Java?
A) IEEE 9000
B) IEEE 800
C) IEEE 754
D) IEEE 512
Answer[=]
C
What is the character encoding standard used in Java language?
A) ASCII
B) Unicode
C) Hexacode
D) Bytecode
Answer[=]
C
What is the abbreviation of ASCII?
A) American Standard Characters for Information Interchange
B) Australian Standard Code for Information Interchange
C) American Standard Code for Information Interchange
D) None of the above
Answer[=]
C
Choose the right statement about Java Data types.
A) Integer data types are short, int and long
B) Real number data types are float and double
C) The character data type is char.
D) All the above
Answer[=]
D
What is Literal in Java?
A) Literal is the value that is given or assigned to a variable.
B) Literal is a data type
C) Literal is similar to String
D) None of the above
Answer[=]
A
What are the types of Integer Literals in Java?
A) Decimal Literals
B) Octal and Hexadecimal Literals
C) Binary Literals
D) All the above
Answer[=]
D
An Octal number is Java is represented with a leading ____?
A) O (Alphabet)
B) 0 (ZERO)
C) 0x
D) 0X
Answer[=]
B
What is the name given to character literals in Java that start with a Back Slash character?
A) Back Slash Sequence
B) Slash Sequence
C) Escape Sequence
D) Extended Sequence
Answer[=]
C
What is the literal in Java that can be used to test whether an Object of any type is alive or
not? 
A) alive
B) liveof
C) null
D) 0
Answer[=]
C
A String literal in Java is surrounded by a pair of _____?
A) Braces
B) Single Quotes
C) Double Quotes
D) Exclamations
Answer[=]
C
Explanation:
A character literal in Java is enclosed within a pair of ___?
A) Square brackets
B) Double Quotes
C) Single Quotes
D) Exclamations
Answer[=]
C
What is the output of this Java snippet?
int a = 0b111;
System.out.println(a);
A) 111
B) 7
C) 8
D) Compiler error
Answer[=]
B
Explanation:
1x2^2 + 1x2^1 + 1x2^0
1x4 + 1x2 + 1
4 + 2 + 1
What are the Type Conversions available in Java language?
A) Narrowing Type Conversion
B) Widening Type Conversion
C) A and B
D) None of the above
Answer[=]
C
What is a Widening Type Conversion in Java?
A) Conversion of data from higher data type to lower data type
B) Conversion of data from lower data type to higher data type
C) Conversion of data from any data type to any data type
D) None of the above
Answer[=]
B
What is a Narrowing Type Conversion in Java?
A) Conversion of data from lower data type to higher data type
B) Conversion data from a higher data type to a lower data type
C) Conversion of data from any data type to any data type
D) None of the above
Answer[=]
B
Type promotion in Java usually refers to ____.
A) Narrowing Type Conversion
B) Widening Type Conversion
C) No Type Conversion
D) None of the above
Answer[=]
B
What is the output of the following Java Code?
int a=9;
float b = a/2;
System.out.println(b);
A) 4.0
B) 4.5
C) 5.0
D) None of the above
Answer[=]
A
Explanation:

You need to type cast at least one number in that expression to float or double to do real
number division.

A boolean literal in Java can be type casted to which data type?


A) byte
B) short
C) int
D) None of the above
Answer[=]
D
If a variable or operand in an expression is type long, then all the operands are type promoted
to which data type?
A) int
B) long
C) float
D) double
Answer[=]
B
Explanation:

All other operands are type promoted to the highest data type available in that expression. If
the highest data type is double in an expression, the final result will also be a double value.

What is the output of the Java code snippet?


int a=5, b=10, c=15;
a -= 3;
b *= 2;
c /= 5;
System.out.println(a +" " + b + " " + c);
A) 2 20 3
B) 2 20 5
C) 2 10 5
D) -2 20 3
Answer[=]
A
Increment and Decrement arithmetic operators in Java has which Associativity?
A) Left to Right
B) Right to Left
C) Left to Left
D) Right to Right
Answer[=]
B
What is the output of the Java code snippet?
int a=10, b=5, c=3;
int d = a+c/2*b;
System.out.println(d);
A) 17.5
B) 32.5
C) 15
D) 30
Answer[=]
C
Choose the correct statement about Java Prefix and Postfix operations.
A) Prefix operation is carried out immediately and the variable value will be incremented or
decremented accordingly
B) Postfix operation is carried out on the next line or statement. So the variable value will not
change.
C) A and B
D) None of the above
Answer[=]
C
What is the other name for Relational Operators in Java?
A) Comparison operators
B) Conditional operators
C) A and B
D) None of the above
Answer[=]
C
What is the output of Java code snippet?
int[] ary = {5,6,7,8};
if(ary.length > 2)
{
System.out.println(ary[2]);
}
A) 6
B) 7
C) 8
D) Compiler error
Answer[=]
B
What is the input for Logical Operators?
A) 1 and 0
B) true / false
C) char / String
D) None of the above
Answer[=]
B
What is the output of a Logical OR (|) operation if both the inputs/operands are true?
A) true
B) false
C) true or false
D) None of the above
Answer[=]
A
Bitwise operators in Java work with?
A) boolean data like true or false
B) Real numbers like float or double
C) Individual bits of integers like byte, short, int, long and char
D) All the above
Answer[=]
C
If relational operators are present in an expression, what type of other operators may be used?
A) Logical operators
B) Bitwise operators
C) A and B
D) None of the above
Answer[=]
A
What is this >>> bitwise operator in Java?
A) Left Shift operator
B) Left Shift Fill Zero operator
C) Right Shift Operator
D) Right Shift Fill Zero operator
Answer[=]
D
What is the output of the Java code snippet?
System.out.println(0b0000_1000);
A) 0b0000_1000
B) 1000
C) 8
D) 9
Answer[=]
C
Explanation:

Binary literals start with 0b. Above number is 8 in decimal notation.

What is the other name for a Question Mark - Colon (?:) operator in Java?
A) Special Relational operator
B) Special Logical Operator
C) Ternary Operator
D) None
Answer[=]
C
The True Part Expression of a Java conditional operator or Ternary operator ____ return a
value.
A) may
B) can
C) must
D) None
Answer[=]
C
Explanation:
The True/False part expression should evaluate to a constant literal.

What is the output of the Java code snippet with Ternary operator?
String name = "java";
int marks = name == "java"?10:20;
System.out.println("Marks=" + marks);
A) marks=0
B) marks=10
C) marks=20
D) Compiler error
Answer[=]
B
What is the output of Java code snippet with a Ternary operator or Conditional operator?
void show()
{
String name = true ? getName() : "FRANCE";
System.out.print(name);
}

void getName()
{
System.out.print("ENGLAND");
}
A) Empty string
B) FRANCE
C) ENGLAND
D) Compiler error
Answer[=]
D
Explanation:

The void functions are not allowed inside a Ternay operator statement.

An IF or ELSE IF statement accepts ___ as input before branching.


A) boolean
B) int
C) float
D) char
Answer[=]
A
The condition of an IF statement evaluates to boolean only if the expression contains?
A) logical operators
B) relational operators
C) boolean operands
D) All
Answer[=]
D
What is the output of the Java program with IF statement?
if(true)
{
break;
System.out.println("ELEPHANT");
}
A) No output
B) ELEPHANT
C) Compiler error
D) None
Answer[=]
C
Which is the alternative to SWITCH in Java language?
A) break, continue
B) for, while
C) if, else
D) goto, exit
Answer[=]
C
A switch statement in Java accepts ___ as input data.
A) enum
B) String
C) enum and String
D) long
Answer[=]
C
Which version of Java did start supporting String as the input data type of a SWITCH?
A) JDK 5
B) JDK 6
C) JDK 7
D) JDK 8
Answer[=]
C
A SWITCH fall through occurs in Java only in the absence of ___.
A) case keyword
B) break keyword
C) default keyword
D) None
Answer[=]
B
Does the following Java code-snippet compile?
switch(45)
{
case 10: ;
}
A) NO
B) YES
C) -
D) -
Answer[=]
B
Explanation:

You can specify dummy statements in java using a Semicolon (;).

Choose the correct statement about Java SWITCH statements.


A) A SWITCH can contain another SWITCH statement.
B) Switch case statements are allowed inside IF-ELSE ladders.
C) Switch statements are allowed inside Loops like for, while and do while.
D) All
Answer[=]
D
A CONTINUE statement inside a Loop like WHILE, FOR, DO-WHILE and Enhanced-FOR
causes the program execution ___ the loop.
A) Skip
B) Skip present iteration and continue with next iteration of the loop
C) Exit
D) None
Answer[=]
B
What is the output of the below Java program?
int a=1;
while(a<4)
{
System.out.print(a + " ");
a++;
}
A) 1 2 3 4
B) 1 2 3
C) 6
D) Compiler error
Answer[=]
B
What is the main difference between a WHILE and a DO-WHILE loop in Java?
A) WHILE loop executes the statements inside of it at least once even if the condition is
false.
B) DO-WHILE loop executes the statements inside of it at least once even if the condition is
false.
C) WHILE loop is fast.
D) DO-WHILE loop is fast.
Answer[=]
B
An enhanced FOR loop work with only Collection type data. Examples of Collection are ___.
A) Array Class type or any regular array variable
B) ArrayList
C) HashMap, HashSet
D) All
Answer[=]
D
What is the output of the below Java code snippet with arrays?
static int[] nums;
public static void main(String args[])
{
System.out.println(nums.length);
}
A) 0
B) null
C) Compiler error
D) Runtime Exception - Null Pointer Exception
Answer[=]
D
What is the output of the below Java program?
int[] marks = {35,65,95};
System.out.print(marks.length + "," + marks[1]);
A) 2,65
B) 3,95
C) 3,65
D) Compiler error
Answer[=]
C
What is the output of the below Java program with arrays?
public class Polo {
public static void main(String args[])
{
String[] computer = {"RAM","HDD","MOUSE"};
String[] parts = {computer[0],computer[2]};
System.out.print(parts[1]);
}
}
A) RAM
B) HDD
C) MOUSE
D) Compiler error
Answer[=]
C
What is the default value of an element of Object type array?
A) 0
B) null
C) -1
D) Garbage value
Answer[=]
B
What is the output of the below Java program with arrays?
String[] ary = {"KITE", "AIR"};
String str = "PLANE";
ary[1] = str;
str = "FLY";
System.out.println(ary[1]);
A) AIR
B) PLANE
C) FLY
D) Compiler error
Answer[=]
B
An array of arrays in Java is called ___ array.
A) Bidirectional
B) Combo
C) Multidimensional
D) Multi-value
Answer[=]
C
Properties are implemented using ___ in Java.
A) Methods
B) Variables
C) Interfaces
D) All the above
Answer[=]
B
In Java programming language, the code is placed inside ___.
A) Classes, Interfaces
B) Methods
C) Blocks
D) All the above
Answer[=]
D
Which is the file extension used for a public Java class source code?
A) .j
B) .class
C) .java
D) None
Answer[=]
C
Which is the file extension used for a compiled Java class file?
A) .j
B) .java
C) .class
D) .cls
Answer[=]
C
In a .java file, how many numbers of public types namely class, interface or abstract can be
managed?
A) 1
B) 2
C) 3
D) Any number
Answer[=]
A
Creating an object from a class is also called ____.
A) Initializing
B) Instantiating
C) Interfacing
D) None of the above
Answer[=]
B
The keyword used to create a new object in Java is ___.
A) class
B) java
C) new
D) create
Answer[=]
C
Choose the correct statements about choosing a name for a class in Java.
A) The class name can start with only a letter or underscore or dollar sign.
B) The class name can contain numbers
C) The class name can not start with a number
D) All the above
Answer[=]
D
An object is created at __ time in Java.
A) Compile-time
B) Run time
C) Assembling time
D) None of the above
Answer[=]
B

M5
What is the return type of the hashCode() method in the Object class?

1. Object
2. int
3. long
4. void

Answer: (b) int

Java method signature is a combination of ___.


A) Return type
B) Method name
C) Argument List
D) All the above
Answer[=]
D
A "this" operator used inside a Java method refers to ___ variable.
A) Global variable
B) Method local variable
C) Instance variable
D) None
Answer[=]
C
What is the output of the below Java program with a "this" operator?
public class TestingMethods4
{
int cakes=5;
void order(int cakes)
{
this.cakes = cakes;
}
public static void main(String[] args)
{
TestingMethods4 t4 = new TestingMethods4();
t4.order(10);
System.out.println("CAKES=" + t4.cakes);
}
}
A) CAKES=5
B) CAKES=0
C) CAKES=10
D) Compiler error
Answer[=]
C
Explanation:

In the program, this.cakes refers to the instance variable cakes.

In Java, local variables are stored in __ memory and instance variables are stored in ___
memory.
A) Stack, Stack
B) Heap, Heap
C) Stack, Heap
D) Heap, Stack
Answer[=]
C
What is the output of the below Java program with a final local variable?
public class TestingMethods8
{
int cars = 20;
void change(final int cars)
{
cars = 10;
this.cars = cars;
}
public static void main(String[] args)
{
TestingMethods8 t8 = new TestingMethods8();
t8.change(30);
System.out.println(t8.cars);
}
}
A) 30
B) 20
C) 10
D) Compiler error
Answer[=]
D
Explanation:

The argument that is marked final can not be reassigned or changed. So, the compiler error is
produced. So, the statement cars=10; inside the change() method is wrong.

A Java constructor is like a method without ___.


A) statements
B) return type
C) argument list
D) None
Answer[=]
B
The purpose of a Java constructor is ___.
A) Initialization of variables with passed data
B) Writing custom code
C) Accepting other objects as inputs
D) All the above
Answer[=]
D
Memory is allocated to an object once the execution of ___ is over in Java language.
A) main method
B) constructor
C) destructor
D) None
Answer[=]
B
Overloading of constructors in Java means adding more than ___ constructors with the
different argument list.
A) 1
B) 2
C) 3
D) 8
Answer[=]
A
A constructor can call another overloaded constructor using the ___ keyword in Java.
A) super
B) local
C) con
D) this
Answer[=]
D
In Java, you can pass __ variables from one constructor to another overloaded constructor.
A) local variables
B) static variables
C) non-static variables
D) local and static variables
Answer[=]
D
Java constructor overloading follows ___ principle in Object-Oriented programming.
A) Inheritance
B) Encapsulation
C) Polymorphism
D) None
Answer[=]
C
To successfully overload a method in Java, the return types must be ___.
A) Same
B) Different
C) Same but using superclass or subclass types also work
D) None
Answer[=]
C
Java uses ___ type of memory to implement Recursion.
A) Heap
B) Stack
C) Register
D) None
Answer[=]
B
Java uses Stack type memory instead of Heap type memory in implementing Recursion
because of ___ feature of STACK.
A) FIFO (First In First Out)
B) LIFO (Last In First Out)
C) Round Robin
D) None
Answer[=]
B
Recursion in Java applies to ___.
A) Constructors
B) Variables
C) Methods
D) Blocks
Answer[=]
C
Which is the common problem with Recursive methods in Java?
A) StackOverflowError
B) IndexOutOfBoundsException
C) OutOfMemoryError
D) None
Answer[=]
A
To end a recursive method a RETURN statement is usually kept inside ___.
A) IF block
B) ELSE block
C) IF or ELSE block
D) None
Answer[=]
C
The command-line arguments are passes at ____.
A) Runtime
B) the time of executing a Java program.
C) the time of compiling a Java program.
D) None
Answer[=]
B
Which is the method that accepts data passed in the form of command-line arguments in
Java?
A) show() method
B) main() method
C) display() method
D) print() method
Answer[=]
B
The type of Arguments the MAIN method accepts is ___.
A) Integer[]
B) Float[]
C) Long[]
D) String[]
Answer[=]
D
The data that is passed at the time of running a Java program as command-line arguments are
converted into ___ data type.
A) Integer array
B) Float array
C) Character array
D) String array
Answer[=]
D
Which is the exception or error that is thrown if a non-existing command-line argument is
referred to in a Java program?
A) StackOverflowError
B) IndexOutOfBoundsException
C) ArrayIndexOutOfBoundsException
D) ArithmeticException
Answer[=]
C
Which are the methods used to parse string values to the respective data types in Java?
A) Boolean.parseBoolean(), Byte.parseByte()
B) Integer.parseInt(), Long.parseLong()
C) Float.parseFloat(), Double.parseDouble()
D) All the above
Answer[=]
D
In a Multi-Level Inheritance in Java, the last subclass inherits methods and properties of
____.
A) Only one immediate Superclass
B) Few classes above it.
C) All classes above it
D) None
Answer[=]
C
Which is the keyword used to implement inheritance in Java?
A) extends
B) implements
C) instanceof
D) None
Answer[=]
A
To control inheritance to different classes and levels, Java provides ____.
A) Return types like the void, int, float, double and other object types
B) Static keyword
C) Access modifiers like default, public, protected, private
D) None
Answer[=]
C

To stop or block inheriting a given class, the ___ keyword is used before the class.
A) static
B) private
C) final
D) none of the above
Answer[=]
C
What is method overriding in Java?
A) Writing a method in a subclass with the same name of superclass's method
B) Mentioning the same return type of the method of the superclass
C) The argument list in the method of subclass and the method of superclass should be the
same
D) All the above
Answer[=]
D
Why should a method be overridden in Java instead of writing a method with a different
name?
A) Large projects heavily depend on inheritance
B) The code-base refers to the same method with the same method signature in different
classes of the project
C) It is not possible to change the method calling code at all occurrences of the project. It
may break the whole project.
D) All the above.
Answer[=]
D
What is the output of the below Java program with method overriding?
class Wood
{
void setQuality(int q)
{
System.out.print(",QUALITY="+q);
}
}
class PlyWood extends Wood
{
void setQuality(char qual)
{
System.out.print(",quality="+qual);
}
}
public class MethodOverriding6
{
public static void main(String[] args)
{
PlyWood pw = new PlyWood();
pw.setQuality(10);
pw.setQuality('B'); //ASCII of B=66
}
}
A) ,QUALITY=10,quality=B
B) ,QUALITY=10,quality=65
C) ,quality=10,quality=B
D) Compiler error
Answer[=]
A
Explanation:

The method "setQuality" is not overridden successfully as the argument types are different.
The subclass type reference can call a method of superclass and subclass.

An Overridden method is the method of ____ class and the overriding method is the method
of ___ class.
A) super, sub
B) sub, super
C) super, super
D) sub, sub
Answer[=]
A
An abstract class in Java can be created using the keyword ____.
A) final
B) interface
C) abstract
D) static
Answer[=]
C
An abstract class in Java usually contains one or more abstract ____.
A) constructors
B) methods
C) variables
D) None
Answer[=]
B
An abstract class with 100% abstract methods is equivalent to ______.
A) Concrete class
B) Virtual Class
C) Interface
D) All the above
Answer[=]
C
Choose a correct statement about abstract classes?
A) An abstract class can extend a concrete class
B) An abstract class can extend another abstract class
C) An abstract class can implement any number of interfaces.
D) All the above.
Answer[=]
D
An interface with no fields or methods is known as a ______.

1. Runnable Interface
2. Marker Interface
3. Abstract Interface
4. CharSequence Interface

Answer: (b) Marker Interface

Which of the given methods are of Object class?

1. notify(), wait( long msecs ), and synchronized()


2. wait( long msecs ), interrupt(), and notifyAll()
3. notify(), notifyAll(), and wait()
4. sleep( long msecs ), wait(), and notify()

Answer: (c) notify(), notifyAll(), and wait()

Which of the following is a mutable class in java?

1. java.lang.String
2. java.lang.Byte
3. java.lang.Short
4. java.lang.StringBuilder

Answer: (d) java.lang.StringBuilder

M6
Which of these classes are the direct subclasses of the Throwable class?

1. RuntimeException and Error class


2. Exception and VirtualMachineError class
3. Error and Exception class
4. IOException and VirtualMachineError class

Answer: (c) Error and Exception class

What do you mean by chained exceptions in Java?

1. Exceptions occurred by the VirtualMachineError


2. An exception caused by other exceptions
3. Exceptions occur in chains with discarding the debugging information
4. None of the above

Answer: (b) An exception caused by other exceptions.

What is the result of the following program?


public static synchronized void main(String[] args) throws  

InterruptedException {  

     Thread f = new Thread();  

      f.start();  

      System.out.print("A");  

      f.wait(1000);  

      System.out.print("B");  

}  

1. It prints A and B with a 1000 seconds delay between them


2. It only prints A and exits
3. It only prints B and exits
4. A will be printed, and then an exception is thrown.

Answer: (d) A will be printed, and then an exception is thrown.

Explanation: The InterruptedException is thrown when a thread is waiting, sleeping, or


occupied. The output of the above code is shown below:

A
Exception in thread "main" java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at com.app.java.B.main(B.java:9)

In the above code, we have created a thread "f," and when started, A will be printed. After
that, the thread will wait for 1000 seconds. Now, an exception is thrown instead of printing B.
It is because the wait() method must be used inside a synchronized block or try-catch block
unless it will throw an exception, as shown above.

Hence, the correct option is option (d).

What is multithreaded programming?


a) It’s a process in which two different processes run simultaneously
b) It’s a process in which two or more parts of same process run simultaneously
c) It’s a process in which many different process are able to access same information
d) It’s a process in which a single process can access information from many sources
View Answer

Answer: b

Thread priority in Java is?


a) Integer
b) Float
c) double
d) long
View Answer

Answer: a

What will happen if two thread of the same priority are called to be processed
simultaneously?
a) Anyone will be executed first lexographically
b) Both of them will be executed simultaneously
c) None of them will be executed
d) It is dependent on the operating system
View Answer

Answer: d

Which of these statements is incorrect?


a) By multithreading CPU idle time is minimized, and we can take maximum use of it
b) By multitasking CPU idle time is minimized, and we can take maximum use of it
c) Two thread in Java can have the same priority
d) A thread can exist only in two states, running and blocked
View Answer

Answer: d

What will be the output of the following Java code?

class multithreaded_programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println(t);
}
}

a) Thread[5,main]
b) Thread[main,5]
c) Thread[main,0]
d) Thread[main,5,main]
View Answer

Answer: d

 What is the name of the method used to start a thread execution?


 A. resume();
 B. run();
 C. start();
 D. init();

 Ans :-  C
M7
Which of the following is an immediate subclass of the Panel class?

1. Applet class
2. Window class
3. Frame class
4. Dialog class

Answer: (a) Applet class

 Which are the common security restrictions in applets?

a. Applets can't load libraries or define native methods


b. An applet can't read every system property
c. Applets can play sounds
d. Both A & B

ANSWER: Both A & B

An applet can play an audio file represented by the AudioClip interface in the java, applet package
Causes the audio clip to replay continually in which method?

a. public void play()


b. public void loop()
c. public void stop()
d. None of the above
ANSWER: public void loop()

 From the following statements which is a drawback for Applet?

a. It works at client side so less response time


b. Secured
c. It can be executed by browsers running under many platforms, including Linux, Windows,
and Mac Os etc.
d. Plugin is required at client browser to execute applet

ANSWER: Plugin is required at client browser to execute applet


 What invokes immediately after the start() method and also any time the applet needs
to repaint itself in the browser?

a. stop()
b. init()
c. paint()
d. destroy()

ANSWER: paint()
Which method is called only once during the run time of your applet?

a. stop()
b. paint()
c. init()
d. destroy()

ANSWER: init()

When an applet is terminated which of the following sequence of methods calls take
place?

a. stop(),paint(),destroy()
b. destroy(),stop(),paint()
c. destroy(),stop()
d. stop(),destroy()

ANSWER: stop(),destroy()

Which is a special type of program that is embedded in the webpage to generate the
dynamic content?

a. Package
b. Applet
c. Browser
d. None of the above
 
ANSWER: Applet
 Which is the correct order of lifecycle in an applet?

a. Applet is started,initialized,painted,destroyed,stopped
b. Applet is painted,started,stopped,initilaized,destroyed
c. Applet is initialized,started,painted,stopped,destroyed
d. None of the above

ANSWER: Applet is initialized,started,painted,stopped,destroyed


 Which applet java.awt.component class provides the life cycle method?

a. public void paint(Graphics g)


b. public void destroy()
c. public void stop()
d. public void init()

ANSWER: public void paint(Graphics g)


 java.applet defines how many interfaces?

a. 2
b. 3
c. 4
d. 5

ANSWER: 3

You might also like