Java 1
Java 1
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
1. Dynamic
2. Architecture Neutral
3. Use of pointers
4. Object-oriented
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
1. Encapsulation
2. Polymorphism
3. Exception
4. Abstraction
Answer: c. Exception
1. Abstraction
2. Encapsulation
3. Polymorphism
4. Inheritance
Answer: d. Inheritance
Which of the following language supports polymorphism but not the classes?
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
1. Only 1
2. Only 999
3. Only 100
4. Any number
1. Overloading <<
2. Overloading &&
3. Overloading | |
4. Overloading +=
Which among the following cannot be used for the concept of polymorphism?
1. student class{ };
2. class student{ student(int a){} };
3. class teacher{ public: teacher(int a){ } };
4. None of the mentioned
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;
}
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
++z + y - y + z + x++
1. 24
2. 23
3. 20
4. 25
Answer: (d) 25
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
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()
You need to type cast at least one number in that expression to float or double to do real
number division.
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 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.
M5
What is the return type of the hashCode() method in the Object class?
1. Object
2. int
3. long
4. void
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.
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
1. java.lang.String
2. java.lang.Byte
3. java.lang.Short
4. java.lang.StringBuilder
M6
Which of these classes are the direct subclasses of the Throwable class?
InterruptedException {
Thread f = new Thread();
f.start();
System.out.print("A");
f.wait(1000);
System.out.print("B");
}
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.
Answer: b
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
Answer: d
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
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
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. 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
a. 2
b. 3
c. 4
d. 5
ANSWER: 3