Java - Online Test - Class - javasearch.buggybread.com


Share

Search Java Test Questions


 223 test questions in repository.




Java - Test Questions on 'Class' - 31 questions found


Which access specifiers can be used with top level class ?Core Java
public or default
public or private
public or protected
protected or default

  access specifier  oops  java  class

Which of the following can be marked static ?Core Java
Methods , Variables and Initialization Blocks.
Methods , Variables , Initialization Blocks and Outer Classes and nested Classes.
Methods , Variables , Initialization Blocks and Outer Classes.
Methods , Variables , Initialization Blocks and nested Classes.

  oops  java  static  nested classes  static nested classes

Which of the following cannot be marked static ?Core Java
Constructors , Classes ( Outer ) , Classes ( nested ), Interfaces , Local variables , Inner Class methods and instance variables.
Constructors , Classes ( Outer ) , Interfaces , Local variables , Class variables , Class Methods , Inner Class methods and instance variables.
Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.
Constructors , Classes ( Outer ) , Classes (Nested), Interfaces , Local variables , Inner Class methods and instance variables.

  oops  java  static  nested classes  static nested classes

Which of the following is not type of inner classes ?Core Java
Simple Inner Class
Static Nested Inner Class
Method Nested Static Inner Class
Anonymous Inner Class

  java  classes  inner classes  nested classes

Which of the following is not the difference between Singleton and Static class ( Class with static members only ) ?Core Java
Only one object can be created for Singleton class whereas No objects are created for static class.
Singleton class instance is initiated using new keyword whereas static class instance is created using static method.
Singleton class can be serialized whereas Static class cannot be.
Singleton Class can participate in runtime Polymorphism whereas Static class cannot.

  java  oops  singleton  design pattern  static class

Which of the following do you think is the primary reason you would never use a static class even the application doesn't need multiple requests or threads ?Core Java
Serialization
Runtime Polymorphism
Lazy Loading
Memory

  static class  static vs singleton  java  oops  objects

Which of the following is not true for abstract classes ?Core Java
Abstract Class is only meant to be sub classed and not supposed to be instantiated.
Abstract class handlers can be used to handle derived class objects.
We can't have an abstract class without abstract methods.
Abstract class has member elements.

  abstract class  abstract methods

Which of following can be nested into another ?Core Java
class within another class
class within interface
interface within class
All of above

  nested classes   nested interface  inner classes

Which of following is not the method of object class ?Core Java
run
notify
wait
clone

  object class

An Ideal Util class doesn't have ...Core Java
private constructor
static methods
static variables
non static methods

  Util classes

Which of the following class cannot be extended or inherited ?

StringBuffer , StringBuilder
Core Java
StringBuffer
StringBuilder
Both cannot be extended
Both can be extended

  final classes  StringBuffer  StringBuilder

Which of the following class creates mutable objects ?Core Java
Boolean
File
String
StringBuffer

  java  immutable

Which of the following statement is not true ?Core Java
x==y means they are pointing to the same object
x==y means that they hold same information
x.equals(y) means they are pointing to the same object
x.equals(y) means that they hold same information

  

When String literals are compared using ==, they always returns true if the string values are same because .. Core Java
of overridden compareTo method
of overridden compare method
of String Pool
== means that the object contents are equal

  

Which of the following has been introduced with Java 8 ?Core Java
StringBuffer
StringBuilder
StringFilter
StringJoiner

  java  java8  java 8  String  StringJoiner

In case of String Literals ..Core Java
x==y on all literals always returns false
x.equals(y) on all literals always returns false
if x.equals(y) returns true, x==y returns true too
if x.equals(y) returns false, x==y returns true

  

What will be the output of following ?

String str1 = new String("String1");
String str2 = new String("String1");
System.out.print(str1 == str2);
System.out.print(str1.equals(str2));
str1 = str2;
System.out.print(str1 == str2);
Core Java
falsetruetrue
truetruetrue
truetruefalse
falsetruefalse

  equals  object equality

What will be the output of following code ?

String str1 = "String1";
String str2 = "String1";
System.out.print(str1 == str2);
System.out.print(str1.equals(str2));
str1 = str2;
System.out.print(str1 == str2);
Core Java
falsetruetrue
falsefalsetrue
truetruetrue
falsefalsefalse

  equals  object equality  string pool

What will be the output of following code ?

String str1 = "String1";
String str2 = "String2";
str1.concat("String3");
System.out.print(str1);
System.out.print(str2);
Core Java
String1String2
String1String3String3
String1String3String1String3
String1String1

  

What will be the output of following code ?

String str1 = "String1";
String str2 = "String2";
str1=str1.concat("String3");
System.out.print(str1);
System.out.print(str2);
Core Java
String1String2
String1String3String2
String1String2String3
String1Stringg3String1

  

Collections is a / an ..Core Java
interface
abstract class
final class
util class

  collections

Which of the following can throw ClassCastException ?Core Java
UpCasting
DownCasting
Casting to incompatible data type
Casting to Strings

  casting

x instanceOf y returns false ..Core Java
if x is an instance of y class
if x is an instance of class implementing y interface
if x is an instance of class extending y class
if x is an instance of Class which is a parent of Y class

  instaceOf

If X implements Y and Y extends Z, Which of the following initialization is correct ?Core Java
X x = new Y();
X x = new Z();
Z z = new Y();
Z z = new X();

  interfaces

If class A implements X interface, and Class B implements Y interface, and X is the parent of Y, Which of the following initialization is correct ?Core Java
A a = new B();
Y y = new A();
X x = new B();
Y y = new A();

  interfaces   inheritance

With the following code, Which is a valid way to initialize ?
public class BuggyBread {

   private String element1;

   private String element2;

   private BuggyBread(String element1, String element2){
      this.element1 = element1;
      this.element2 = element2;
   }

   public static class Builder {
   
      private String element1;

      private String element2;

      Builder(BuggyBread buggybread){
         element1 = buggybread.element1;
         element2 = buggybread.element2;
      }

      Builder withElement1(String element1){
         this.element1 = element1;
         return this;
      }

      Builder withElement2(String element2){
         this.element2 = element2;
         return this;
      }

      BuggyBread build(){
         BuggyBread buggybread = new BuggyBread(element1,element2);
         return buggybread;
      }
   }
}
Core Java
BuggyBread buggybread = new BuggyBread();
BuggyBread buggybread = new BuggyBread("element1","element2");
BuggyBread.Builder builder = new BuggyBread.Builder();
BuggyBread.Builder builder = new BuggyBread.Builder("element1","element2");

  builder pattern

What will be the output of exceuting main method ?

public static void main(String[] args){
      List list = new ArrayList();
      list.add(1);
      list.add(2);
      list.add(3);
      System.out.println(list);
   }
Core Java
1,2,3
Order cannot be determined
compilation error
3,2,1

  collections  list  arraylist

Which of the following class creates immutable objects ?Core Java
String
StringBuffer
StringBuilder
None of these create immutable objects.

  String  StringBuffer  StringBuilder  Immutable

Which of the following class is synchronized ?Core Java
String
StringBuffer
StringBuilder
None of these

  String  StringBuffer  StringBuilder  Synchronized

What is the problem with this code ?

public class Car extends Vehicle{   
   int x;
   
   Car(int y){
      x = 5;
   }
   
   Car(){
      this(5);
      super();
   }
}
Core Java
We cannot overload constructors
Constructors should have type
we should have called super() before this(5)
We cannot have both super() and this() in a constructor

  Constructor  this  super

Which memory segment holds String Pool ?Core Java
Stack
Heap
Code Segment
Class Segment

  memory management  string pool







comments powered by Disqus