0% found this document useful (0 votes)
289 views27 pages

Mock Exam 3

This document contains 25 multiple choice questions about Java programming concepts. For each question, the text of the question and possible answer options are provided, along with feedback indicating the correct answer. The questions cover topics such as data types, operators, classes, inheritance, polymorphism, abstract classes, interfaces, and more. Not all questions were attempted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
289 views27 pages

Mock Exam 3

This document contains 25 multiple choice questions about Java programming concepts. For each question, the text of the question and possible answer options are provided, along with feedback indicating the correct answer. The questions cover topics such as data types, operators, classes, inheritance, polymorphism, abstract classes, interfaces, and more. Not all questions were attempted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Question 1

Correct
Mark 1.00 out of 1.00

Flag question

Question text

which of the following is the reference data type ?

Select one:
a. short
b. array 
c. int

d. double
Feedback

The correct answer is: array

Question 2
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following can be operands of arithmetic operators?

Select one:
a. Boolean
b. Numeric
c. Characters

d. Both Boolean & Characters 


Feedback

The correct answer is: Both Boolean & Characters

Question 3
Correct
Mark 1.00 out of 1.00

Flag question

Question text
A class Car and its subclass Yugo both have a method run() which was written by the
programmer as part of the class definition. If junker refers to an object of type Yugo,
what will the following code do?
junker.show();

Select one:
a. The show() method defined in Car will be called.
b. Overloading will be used to pick which run() is called.
c. The compiler will complain that run() has been defined twice.

d. The show() method defined in Yugo will be called. 


Feedback

The correct answer is: The show() method defined in Yugo will be called.

Question 4
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

What is the process of defining more than one method in a class differentiated by
method signature?

Select one:
A. Function overloading
B. Function doubling
C. None of the mentioned

D. Function overriding 
Feedback

The correct answer is: Function overloading

Question 5
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following statement is incorrect?

Select one:
a. There can be only one main() method in a program.
b. main() method must be made public.
c. Applets do not require a main() method at all.

d. Every class must contain a main() method. 


Feedback

The correct answer is: Every class must contain a main() method.

Question 6
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

What is the output of this program?

1.     class main_class {
2.         public static void main(String args[])
3.         {
4.             int x = 9;
5.             if (x == 9) {
6.                 int x = 8;
7.                 System.out.println(x);
8.             }
9.         }
10.     }

Select one:
a. Compilation error
b. 9
c. 8

d. Runtime error 
Feedback

The correct answer is: Compilation error

Question 7
Correct
Mark 1.00 out of 1.00

Flag question
Question text

Which of these is not a correct statement?

Select one:
A. Abstract class can be initiated by new operator 
B. Abstract class defines only the structure of the class not its implementation
C. Every class containing abstract method must be declared abstract

D. Abstract class can be inherited


Feedback

The correct answer is: Abstract class can be initiated by new operator

Question 8
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What is the output of this program?


1. class A {
2. public void display() {
3. System.out.println("A");
4. }
5. }
6. class B extends A {
7. public void display() {
8. System.out.println("B");
9. }
10. }
11. class Dynamic_dispatch {
12. public static void main(String args[])
13. {
14. A obj1 = new A();
15. B obj2 = new B();
16. A r;
17. r = obj1;
18. r.display();
19. r = obj2;
20. r.display();
21. }
22. }

Select one:
A.  B A
B. A B 
C. Runtime Error

D. Compilation Error
Feedback

The correct answer is: A B

Question 9
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What is not true about applets? 

Select one:
a. Applets shoud be run under a Java-compatible browser
b. Applets do not need a main() method
c. User I/O is accomplished with Java's stream I/O classes 

d. Applet uses the interface provided by AWT


Feedback

The correct answer is: User I/O is accomplished with Java's stream I/O classes

Question 10
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What is the return type of a method that does not returns any value?

Select one:
A. double
B. int
C.  float

D.  void 
Feedback

The correct answer is:  void

Question 11
Not answered
Marked out of 1.00

Flag question

Question text

What will be the output of the following Java code?


class A
{
int i;
int j;
A()
{
i = 1;
j = 2;
}
}
class Output
{
public static void main(String args[])
{
A obj1 = new A();
System.out.print(obj1.toString());
}
}

Select one:
A. String associated with obj1
B. false
C. Compilation Error

D. true
Feedback

The correct answer is: String associated with obj1

Question 12
Not answered
Marked out of 1.00
Flag question

Question text

What is an event in delegation event model used by Java programming language?

Select one:
A. An event is an object that describes a state change in processing.
B. An event is a class used for defining object, to create events.
C. An event is an object that describes any change by the user and system.

D. An event is an object that describes a state change in a source.


Feedback

The correct answer is: An event is an object that describes a state change in a source.

Question 13
Not answered
Marked out of 1.00

Flag question

Question text

An ________  class is super class of every class in Java?

Select one:
a. Object class
b. ArrayList class
c. Abstract class

d. String class
Feedback

The correct answer is: Object class

Question 14
Not answered
Marked out of 1.00

Flag question

Question text

Which of the following option leads to the portability and security of Java?
Select one:
A. The applet makes the Java code secure and portable
B. Bytecode is executed by JVM
C. Use of exception handling

D. Dynamic binding between objects


Feedback

The correct answer is: Bytecode is executed by JVM

Question 15
Not answered
Marked out of 1.00

Flag question

Question text

Which of these operators is used to allocate memory to array variable in Java?

Select one:
A.  alloc
B.  malloc
C.  new

D.  new malloc
Feedback

The correct answer is:  new

Question 16
Not answered
Marked out of 1.00

Flag question

Question text

Which of these keywords are used to define an abstract class?

Select one:
A. Abstract
B. abstract class
C. abstract

D. Abst
Feedback

The correct answer is: abstract

Question 17
Not answered
Marked out of 1.00

Flag question

Question text

Identify the incorrect statement from the following options?


I) The left shift operator, <<, shifts all of the bite in a value to the left specified number
of times.
II) The right shift operator, >>, shifts all of the bite in a value to the right specified
number of times.
III) The left shift operator can be used as an alternative to multiplying by 2.
IV) The right shift operator automatically fills the higher order bits with 0.

Select one:
a. II
b. I
c. IV

d. III
Feedback

The correct answer is: IV

Question 18
Not answered
Marked out of 1.00

Flag question

Question text

Which of the following loops will execute the body of loop even when condition
controlling the loop is initially false?

Select one:
a. while
b. do-while
c. None
d. for
Feedback

The correct answer is: do-while

Question 19
Not answered
Marked out of 1.00

Flag question

Question text

What is the correct JDK command to compile a class in the file Test.java

Select one:
a. compile Test.java
b. java Test
c. javac Test.java

d. javac Test
Feedback

The correct answer is: javac Test.java

Question 20
Not answered
Marked out of 1.00

Flag question

Question text

What is the value stored in the object obj Ref to the line of code below?
box obj;

Select one:
a. NULL
b. Garbage
c. Memory address of allocated memory of an object.

d. Any arbitrary pointer


Feedback

The correct answer is: NULL

Question 21
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

What will be the output of the following program?


public class MyFirst {
public static void main(String[] args) {
MyFirst obj = new MyFirst(n);
}
static int a = 10;
static int n;
int b = 5;
int c;
public MyFirst(int m) {
System.out.println(a + ", " + b + ", " + c + ", " + n + ", " + m);
}
// Instance Block
{
b = 30;
n = 20;
}
// Static Block
static
{
a = 60;
}
}

Select one:
A. 10, 30, 20 
B. 10, 5, 0, 20, 0
C. 60, 5, 0, 20

D. 60, 30, 0, 20, 0


Feedback

The correct answer is: 60, 30, 0, 20, 0

Question 22
Correct
Mark 1.00 out of 1.00

Flag question
Question text

What is the output of this program?


class string_class {
          public static void main(String args[])
    {
                    String obj = "hello";
                    String obj1 = "world";
                    String obj2 = "hello";
                    System.out.println(obj.equals(obj1) + " " + obj.equals(obj2));
     }
}

Select one:
a. true true
b. false false
c. true false

d. false true 
Feedback

The correct answer is: false true

Question 23
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of these operators is used to allocate memory for an object?

Select one:
A. new 
B.  give
C. Amalloc

D.  alloc
Feedback
The correct answer is: new

Question 24
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Range of short variable is ______________

Select one:
A. -128 to 127
B. -32768 to 32767 
C. -32768 to 32768

D. -128 to 128
Feedback

The correct answer is: -32768 to 32767

Question 25
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which interface provides the capability to store objects using a key-value pair?

Select one:
a. java.util.Set
b. java.util.Map 
c. Java.util.Collection

d. java.util.List
Feedback

The correct answer is: java.util.Map

Question 26
Correct
Mark 1.00 out of 1.00

Flag question
Question text

Which one is a valid declaration of a boolean?

Select one:
a. boolean b2 = ‘false’;
b. boolean b3 = false; 
c. boolean b1 = 1;

d. boolean b4 = ‘true’
Feedback

The correct answer is: boolean b3 = false;

Question 27
Not answered
Marked out of 1.00

Flag question

Question text

If a class inheriting an abstract class does not define all of its function then it will be
known as?

Select one:
A. A simple class
B. Abstract
C. None of the option mentioned

D. Static class
Feedback

The correct answer is: Abstract

Question 28
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

which of the following data types comes under floating data types ?

Select one:
a. float
b. byte
c. int

d. long 
Feedback

The correct answer is: float

Question 29
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of these cannot be declared static?

Select one:
A. object 
B. class
C. method

D. variable
Feedback

The correct answer is: object

Question 30
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What is the output of this program?


1.      class exception_handling {
2.          publicstaticvoid main(String args[]){
3.              try{
4.                  int i, sum;
5.                  sum =10;
6.                  for(i =-1; i <3;++i){
7.                      sum =(sum / i);
8.                  System.out.print(i);
9.                  }
10.            }
11.            catch(ArithmeticException e){         
12.                System.out.print("0");
13.            }
14.        }
15.    }

Select one:
a. 0
b. -1
c. -101

d. -10 
Feedback

The correct answer is: -10

Question 31
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What is the output of this program?

1.     class Relational_operator {
2.         public static void main(String args[])
3.         {
4.             int var1 = 5;
5.             int var2 = 6;
6.             System.out.print(var1 > var2);
7.         }
8.     }

Select one:
a. 0
b. 1
c. true
d. false 
Feedback

The correct answer is: false

Question 32
Correct
Mark 1.00 out of 1.00

Flag question

Question text

When a class extends the Thread class ,it should override…… method of Thread class to
start that thread.

Select one:
a. go()
b. start()
c. init()

d. run() 
Feedback

The correct answer is: run()

Question 33
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

Which of these statement is correct?

Select one:
A. true and false are numeric values 1 and 0. 
B. true and false are numeric values 0 and 1.
C. true is any non zero value and false is 0.

D. true and false are non numeric values.


Feedback

The correct answer is: true and false are non numeric values.
Question 34
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following sequence of method calls take place when an applet begins? 

Select one:
a. init(), start(), create()
b. start(), init(), paint()
c. init(), start(), paint() 

d. start(), init(),  create()
Feedback

The correct answer is: init(), start(), paint()

Question 35
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

Which of these keywords can be used to prevent Method overriding?

Select one:
A.  protected
B. constant
C. static 

D. final
Feedback

The correct answer is: final

Question 36
Correct
Mark 1.00 out of 1.00

Flag question

Question text
What is the output of this program?

1.     class Output {
2.         public static void main(String args[])
3.         {   
4.              int x, y = 1;
5.              x = 10;
6.              if (x != 10 && x / 0 == 0)
7.                  System.out.println(y);
8.              else
9.                  System.out.println(++y);
10.             }
11.         }

Select one:
a. 2 
b. Runtime error owing to division by zero in if condition.
c. 1

d. Unpredictable behaviour of program.


Feedback

The correct answer is: 2

Question 37
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What is the output of this program?

1.     class box {
2.         int width;
3.         int height;
4.         int length;
5.         int volume;
6.         void volume() {
7.              volume = width*height*length;
8.         }
9.     }   
10.     class Output {
11.         public static void main(String args[])
12.         {
13.             box obj = new box();
14.             obj.height = 1;
15.             obj.length = 5;
16.             obj.width = 5;
17.             obj.volume();
18.             System.out.println(obj.volume);       
19.         }
20.     }

Select one:
a. 26
b. 25 
c. 1

d. 0
Feedback

The correct answer is: 25

Question 38
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

Which of the following is correct syntax for defining a new class Jolt based on the
superclass SoftDrink?  

Select one:
a. class Jolt defines SoftDrink
{
//additional definitions go here
}
b. class Jolt implements SoftDrink
{
//additional definitions go here

c. class Jolt isa SoftDrink
{
//additional definitions go here
}

d. class Jolt extends SoftDrink


{
//additional definitions go here
}
Feedback

The correct answer is: class Jolt extends SoftDrink


{
//additional definitions go here
}

Question 39
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What will be the output of the following Java code?


class A
{
public int i;
public int j;
A()
{
i = 1;
j = 2;
}
}
class B extends A
{
int a;
B()
{
super();
}
}
class super_use
{
public static void main(String args[])
{
B obj = new B();
System.out.println(obj.i + " " + obj.j)
}
}

Select one:
A. 1 2 
B. Runtime Error
C. Compilation Error

D. 2 1
Feedback

The correct answer is: 1 2

Question 40
Not answered
Marked out of 1.00

Flag question

Question text

The constructor for Font class is…………….

Select one:
a. Font(String name)
b. Font(String name,int style)
c. Font(string name,int style,int size)

d. Font(String name,int size)


Feedback

The correct answer is: Font(string name,int style,int size)

Question 41
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

Thread priority in Java is?

Select one:
A. long
B. double 
C. Integer

D.  Float
Feedback

The correct answer is: Integer

Question 42
Correct
Mark 1.00 out of 1.00

Flag question

Question text

To resume a thread after suspendeing it…..method is used

Select one:
a. restart()
b. resume() 
c. start()

d. run()
Feedback

The correct answer is: resume()

Question 43
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following is NOT defined by applet class? 

Select one:
a. start()
b. init() 
c. paint()

d. none of these
Feedback

The correct answer is: init()

Question 44
Correct
Mark 1.00 out of 1.00
Flag question

Question text

Which of these package is used for all the text related modifications?

Select one:
a. java.text 
b. java.awt
c. java.lang.text

d. java.text.mofify
Feedback

The correct answer is: java.text

Question 45
Not answered
Marked out of 1.00

Flag question

Question text

The base class of the classes "Button" and "TestComponent" is 

Select one:
a. Objects
b. Component
c. Container

d. Label
Feedback

The correct answer is: Component

Question 46
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

What is the output of this program?

1.     class area {
2.         public static void main(String args[])
3.         {   
4.              double r, pi, a;
5.              r = 9.8;
6.              pi = 3.14;
7.              a = pi * r * r;
8.              System.out.println(a);
9.         }
10.     }

Select one:
a. 301.5656
b. 301.56560000 
c. 301

d. 301.56
Feedback

The correct answer is: 301.5656

Question 47
Not answered
Marked out of 1.00

Flag question

Question text

What is process of defining two or more methods within same class that have same
name but different parameters declaration?

Select one:
A. method overloading
B. None of the mentioned
C. method hiding

D. method overriding
Feedback

The correct answer is: method overloading

Question 48
Not answered
Marked out of 1.00

Flag question
Question text

Which of these statements are incorrect?


I) Assignment operators are more efficiently implemented by Java run-time system than
their equivalent long forms.
II) Assignment operators run faster than their equivalent long forms.
III) Assignment operators can be used only with numeric and character data type.

Select one:
a. None of these statements are incorrect.
b. Statement I
c. Statement II

d. Statement III
Feedback

The correct answer is: None of these statements are incorrect.

Question 49
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

Which of these package is used for handling security related issues in a program?

Select one:
a. java.lang.security 
b. java.security
c. java.io.security

d. java.awt.image
Feedback

The correct answer is: java.security

Question 50
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text
What is the output of this program?
class Output {
        static void main(String args[])
        {   
             int x , y = 1;
             x = 10;
             if (x != 10 && x / 0 == 0)
                 System.out.println(y);
             else
                 System.out.println(++y);
        }
    }

Select one:
a. 2 
b. 1
c. Runtime Error

d. Compilation Error
Feedback

The correct answer is: Compilation Error

You might also like