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


Share

Search Java Test Questions


 223 test questions in repository.




Java - Test Questions on 'Private' - 3 questions found


How can we create objects if we make the constructor private ?Core Java
We can't create objects if constructor is private
We can only create objects if we follow singleton pattern
We can only create one object
We can create new object through static method or static block

  constructor   private constructor

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

What will be the output of following code ?

public class BuggyBread {

   private int x;
   private Integer y;

   private BuggyBread(int x,int y){};

   public static void main(String[] args){
      BuggyBread buggybread = new BuggyBread(1,2);
      System.out.println(buggybread.x);
   }
}
Core Java
compilation error due to private constructor
compilation error due to uninitialized elements
0 null
0 0

  constructor







comments powered by Disqus