Java Classes and Objects Interview MCQ Questions and Answers 2

Study and learn Interview MCQ Questions and Answers on Java Classes and Objects. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes Classes and Java Theory Notes on Objects before reading these objective questions.



1) What is the output of the below Java program with two classes?
//Testing1.java
public class Example
{
	
}
public class Testing1
{
  public static void main(String[] args)
  {
    System.out.println("Hello Boss.!");
  }
}
A) Hello Boss.!
B) No Output
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
2) What is the output of the below Java program?
//bingo.java file
public class Hello
{
  public static void main(String[] args)
  {
    System.out.println("BINGO");
  }
}
A) bingo
B) BINGO
C) Compiler error
D) None
Answer [=]
Answer[=]
3) State TRUE or FALSE. A Java class provides encapsulation.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
4) What is the output of the below java class?
class Fox
{
  int legs = 2;
}
class Testing2
{
  public static void main(String[] args)
  {
    Fox t1 = new Fox();
    System.out.println("T1 before: " + t1.legs);
    t1.legs = 4;
    System.out.println("T1 After: " + t1.legs);
  }
}
A)
T1 before: 4
T1 After: 4
B)
T1 before: 2
T1 After: 2
C)
T1 before: 2
T1 After: 4
D) Compiler error
Answer [=]
Answer[=]
5) The value of one primitive variable is assigned to another primitive variable by ___ in Java.
A) Pass by value
B) Pass by reference
C) -
D) -
Answer [=]
Answer[=]
6) A primitive variable is passed from one method to another method by ___ in Java.
A) Pass by value
B) Pass by reference
C) -
D) -
Answer [=]
Answer[=]
7) An object or primitive value that is passed from one method to another method is called ___ in Java. (Argument / Parameter)
A) Argument
B) Parameter
C) -
D) -
Answer [=]
Answer[=]


 

8) An object or a primitive value that is received in a method from another method is called ___ in Java. (Argument / Parameter)
A) Argument
B) Parameter
C) -
D) -
Answer [=]
Answer[=]
9) What is the output of the below Java program that passes an object to another method?
class Food
{
  int items;
  int show()
  {return items;}
}

class Testing9
{
  public static void main(String[] args)
  {
    Food f = new Food();
    f.items = 5;
    System.out.println("Items Before = " + f.show());
    change(f);
    System.out.println("Items After = " + f.show());
  }
  static void change(Food foo)
  { foo.items = 10; }
}
A)
Items Before = 10
Items After = 10
B)
Items Before = 5
Items After = 5
C)
Items Before = 5
Items After = 10
D)
Items Before = 10
Items After = 5
Answer [=]
Answer[=]
10) What is the output of the below Java program that passes primitive values?
class Testing10
{
  int rats = 5;

  public static void main(String[] args)
  {
    Testing10 t1 = new Testing10();
    System.out.println("Rats Before = " + t1.rats);
    modify(t1.rats);
    System.out.println("Rats After = " + t1.rats);
  }
  static void modify(int r)
  { r = 20; }
}
A)
Rats Before = 5
Rats After = 5
B)
Rats Before = 20
Rats After = 20
C)
Rats Before = 5
Rats After = 20
D)
Rats Before = 20
Rats After = 5
Answer [=]
Answer[=]
11) Java object assignment happens by ___.
A) Pass by Value
B) Pass by Reference
C) -
D) -
Answer [=]
Answer[=]
12) Java object passing from one method to another method happens by ___.
A) Pass by Value
B) Pass by Reference
C) -
D) -
Answer [=]
Answer[=]
13) In Java Pass by reference ___ is passed even if you are passing a reference to an object.
A) Address value
B) Variable value
C) Hash code
D) None of the above
Answer [=]
Answer[=]
14) A Java reference is comparable to ___ in C language.
A) Enum
B) Structure
C) Pointer
D) None
Answer [=]
Answer[=]


 

15) ___ is the superclass to all Java classes either user-defined or built-in.
A) Class
B) Object
C) Superclass
D) Null
Answer [=]
Answer[=]
16) State TRUE of FALSE. Java objects have built-in methods to handle threads.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
17) State TRUE or FALSE. Java Object's hashcode() method is mainly used with Collection objects.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
18) What is the output of the below Java program using toString() method?
class College
{
  public String toString()
  { return "College Object"; }
}
class Testing18
{
  public static void main(String[] args)
  {
    College col = new College();
    System.out.println("Printing Object=" + col);
  }
}
A) Printing Object=
B) Printing Object=null
C) Printing Object=College Object
D) Compiler error
Answer [=]
Answer[=]
19) What is the output of the below Java program?
class Cricket
{ int runs; }

class Testing19
{
  public static void main(String[] args)
  {
    Cricket c1 = new Cricket();
    c1.runs = 250;
    Cricket c2;
    c2 = c1;
    c2.runs = 300;
    System.out.println("Runs= " + c1.runs);
  }
}
A) Runs= 0
B) Runs= 250
C) Runs= 300
D) Compiler error
Answer [=]
Answer[=]
20) What is the output of the below Java program?
class Wordpress
{ int posts; }
class Testing20
{
  public static void main(String[] args)
  {
    Wordpress wp1 = new Wordpress();
    wp1.posts = 25;
    Wordpress wp2 = wp1;
    wp1 = null;
    System.out.println("Posts=" + wp2.posts);
  }
}
A) Posts=25
B) Posts=0
C) Posts=null
D) Runtime exception occurs
Answer [=]
Answer[=]


Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Try Some Java Books

Book Price
1. Java - The Complete Reference  Check Price
2. Core Java: An Integrated Approach, Black Book Check Price
3. Java All-in-One for Dummies Check Price
4. OCP Java SE 8: Programmer II Check Price
5. Programming with Java Check Price
6. Head First Java Check Price

We may get some affiliate commission for the above purchases.