Java Pool Bit Meerut

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Ankur_bit
A
Ankur_bit
Community Contributor
Quizzes Created: 1 | Total Attempts: 114
Questions: 30 | Attempts: 114

SettingsSettingsSettings
Java Pool Bit Meerut - Quiz


testing java by online exam


Questions and Answers
  • 1. 

    What is java ?

    • A.

      Oop language

    • B.

      Structure language

    • C.

      Procedural language

    • D.

      Application language

    • E.

      Software devlopment language

    Correct Answer
    A. Oop language
    Explanation
    Java is an object-oriented programming (OOP) language. It is designed to follow the principles of OOP, which include encapsulation, inheritance, and polymorphism. Java allows developers to create modular and reusable code by creating objects and classes. It provides features like inheritance, polymorphism, and abstraction, which make it easier to design and implement complex software systems. Java is widely used for developing various types of applications, including desktop, web, and mobile applications.

    Rate this question:

  • 2. 

    Which of these is a keyword in java?

    • A.

      Goto

    • B.

      Enum

    • C.

      Switch

    • D.

      Class

    • E.

      Critical

    Correct Answer(s)
    A. Goto
    B. Enum
    C. Switch
    D. Class
    Explanation
    In Java, "enum", "switch", and "class" are all keywords. Keywords are reserved words that have a specific meaning in the programming language and cannot be used as identifiers. "goto" and "critical" are not keywords in Java.

    Rate this question:

  • 3. 

    Which is legal identifier name?

    • A.

      Int __;

    • B.

      Int $_1;

    • C.

      Int 123;

    • D.

      Int a*g;

    • E.

      Int th_is;

    Correct Answer(s)
    A. Int __;
    B. Int $_1;
    E. Int th_is;
    Explanation
    The legal identifier names in this question are "int __;", "int $_1;", and "int th_is;". The first two options use underscores and dollar signs, which are allowed characters in identifier names. The third option uses a combination of letters and underscores, which is also a valid identifier name.

    Rate this question:

  • 4. 

    "Tiger" is used to denote which version of java?

    • A.

      Java 5.0

    • B.

      Java 6.0

    • C.

      Java 1.1

    • D.

      Java 1.0

    • E.

      Java 2.0

    Correct Answer
    A. Java 5.0
    Explanation
    "Tiger" is a code name used to refer to Java 5.0. Code names are often used by software developers to refer to different versions of their software during development. In the case of Java 5.0, it was given the code name "Tiger" before its official release. Therefore, "Tiger" is used to denote Java 5.0.

    Rate this question:

  • 5. 

    Which one of these is primitive datatype in java?

    • A.

      Int

    • B.

      Boolean

    • C.

      Short

    • D.

      Long

    • E.

      Float

    Correct Answer(s)
    A. Int
    B. Boolean
    E. Float
    Explanation
    The primitive data types in Java are int, boolean, and float. These data types are considered primitive because they are not objects and do not have any methods or properties associated with them. They are basic building blocks in Java and are used to store simple values such as integers, true/false values, and decimal numbers. Short and Long are not considered primitive data types in Java as they are wrapper classes for the primitive data types short and long respectively.

    Rate this question:

  • 6. 

    Try{int x=Integer.parseInt("two");}what type of exceptions can be caugth in catch block?

    • A.

      IllegalStateException

    • B.

      IllegalArgumentException

    • C.

      NumberFormatException

    • D.

      IllegalMonitorStateException

    • E.

      ArrayIndexOutOfBoundException

    Correct Answer(s)
    B. IllegalArgumentException
    C. NumberFormatException
    Explanation
    The code snippet is attempting to convert the string "two" into an integer using the parseInt() method. However, since "two" cannot be converted into a valid integer, it will throw a NumberFormatException. Additionally, since the code does not handle any other exceptions specifically, any other exception that may occur during the execution of the code will be caught by the catch block as a general Exception. Therefore, the correct answer is IllegalArgumentException and NumberFormatException.

    Rate this question:

  • 7. 

    Class A{static void sing(){System.out.print("fa");}}class B extends A{static void sing(){System.out.print("la";)}public static void main(String[] args){A one=new B();B two=new B();System.out.print(one.sing()+""+two.sing());}}}what is the result?

    • A.

      Fa la

    • B.

      La fa

    • C.

      Fa fa

    • D.

      La la

    • E.

      Compilation fails

    Correct Answer
    A. Fa la
    Explanation
    The code defines two classes, A and B. Class B extends class A. Both classes have a static method called "sing" that prints out a string. In the main method, two objects are created, one of type A and one of type B. The "sing" method of class A is called on the object of type A, which prints "fa". The "sing" method of class B is called on the object of type B, which prints "la". Therefore, the output of the code is "fa la".

    Rate this question:

  • 8. 

    Class Top{Top(String s){System.out.println("Hello");}}class Bottom extends Top{Bottom(String t){}public static void main(String[] args){new Bottom("BIT"); }}what is the result?

    • A.

      Hello

    • B.

      No output is generated

    • C.

      An Exception is thrown at run time

    • D.

      Compilation fail

    • E.

      None of above

    Correct Answer
    D. Compilation fail
    Explanation
    The given code will result in a compilation fail. This is because the class Bottom is extending the class Top, but it does not have a constructor that calls the constructor of the superclass. Since the superclass constructor is not explicitly called in the subclass constructor, the compiler will generate a default constructor for the subclass. However, the default constructor in the superclass requires a String parameter, so the compiler will not be able to generate a default constructor for the subclass, resulting in a compilation error.

    Rate this question:

  • 9. 

    Class Alpha{int over=1;}class Beta extends Alpha{int over=2; }class Gamma extends Beta{int over=3;public static void main(String[] args){new Gamma().go();}void go(){Beta b=new Gamma();Alpha a=new Gamma();System.out.println(super.over+""+b.over+""+a.over);}}what is the result?

    • A.

      221

    • B.

      321

    • C.

      233

    • D.

      333

    • E.

      Compilation fails

    Correct Answer
    A. 221
    Explanation
    The program creates an object of the Gamma class and calls the go() method. Inside the go() method, a Beta object is created and assigned to the variable 'b', and an Alpha object is created and assigned to the variable 'a'.

    The 'super.over' expression inside the println statement refers to the 'over' variable in the parent class Beta, which has a value of 2. The 'b.over' expression refers to the 'over' variable in the Beta class, which has a value of 2. The 'a.over' expression refers to the 'over' variable in the Alpha class, which has a value of 1.

    Therefore, the output will be "221".

    Rate this question:

  • 10. 

    Public class Switch2{public static short x=1;staticfinal int y=3;public static void main(String[] args){for(int z=3;z>0;--z){switch(z){case y:System.out.print("0");case y-1:System.out.print("1");case x:z--;}}}}what is the result?

    • A.

      01

    • B.

      012

    • C.

      Compilation fails at line 7

    • D.

      Compilation fails at line 8

    • E.

      Compilation fails at line 9

    Correct Answer
    E. Compilation fails at line 9
    Explanation
    The compilation fails at line 9 because the variable "x" is not a constant expression. In a switch statement, the cases must be constant expressions, but "x" is a variable and its value can change. Therefore, the code will not compile.

    Rate this question:

  • 11. 

    Class Zeta{public static void main(String[] args){int x=1;if((4>x)^((++x + 2)>3)) x++;if((4 > ++x)^(++x==5)) x++;System.out.print(x);}}what is the result?

    • A.

      2

    • B.

      3

    • C.

      4

    • D.

      5

    • E.

      Compilation fails

    Correct Answer
    C. 4
    Explanation
    In this code, the variable x is initially assigned a value of 1. The first if statement checks if (4 > x) is true, which is false because x is 1. The second part of the if statement is ((++x + 2) > 3), which is true because x is incremented to 2 and 2 + 2 is greater than 3. Since the first part of the if statement is false and the second part is true, the XOR operator (^) returns true. Therefore, x is incremented to 2. The second if statement checks if (4 > ++x) is true, which is false because x is now 3. The second part of the if statement is (++x == 5), which is false because x is incremented to 4 and 4 is not equal to 5. Since both parts of the if statement are false, the XOR operator returns false. Therefore, x remains 3. Finally, the value of x (which is 3) is printed.

    Rate this question:

  • 12. 

    Which are true?

    • A.

      A static method cannot be synchronized.

    • B.

      If a class has synchronized code,multiple threads can still access the non-synchronized code.

    • C.

      Variables can be marked synchronized

    • D.

      When a thread sleeps,it releases its locks

    • E.

      When a thread invockes wait(),it releases its locks

    Correct Answer(s)
    B. If a class has synchronized code,multiple threads can still access the non-synchronized code.
    E. When a thread invockes wait(),it releases its locks
    Explanation
    When a class has synchronized code, multiple threads can still access the non-synchronized code. This means that even if some parts of the class are synchronized and only one thread can access them at a time, other threads can still access the non-synchronized parts simultaneously. This can lead to potential concurrency issues and unexpected behavior.

    When a thread invokes the wait() method, it releases its locks. This means that when a thread is waiting for a certain condition to be met, it releases any locks it holds, allowing other threads to acquire those locks and continue their execution. This is important for proper synchronization and coordination between multiple threads.

    Rate this question:

  • 13. 

    Public class MyProgram{public static void main(String[] args){try{  System.out.print("Hello World");}finally{System.out.println("Finally executing");}}}what is the result?

    • A.

      Compilation fails

    • B.

      Exception

    • C.

      Hello world

    • D.

      Hello world Finally executing

    • E.

      Finally executing Hello world

    Correct Answer
    D. Hello world Finally executing
    Explanation
    The program will print "Hello World" and then execute the code in the finally block, which will print "Finally executing". Therefore, the result will be "Hello World Finally executing".

    Rate this question:

  • 14. 

    Class Alpha{int doStuff(float b){return 7;}}class Beta extends Alha{//insert code here}which,inserted independently at line 8,will compile?

    • A.

      Private int doStuff(float y){return 4;}

    • B.

      Protected int doStuff(float y){return 4;}

    • C.

      Public Integer doStuff(float y){return 4;}

    • D.

      Final int doStuff(float y){return 4;}

    • E.

      Public long doStuff(float y){return 4;}

    Correct Answer(s)
    B. Protected int doStuff(float y){return 4;}
    D. Final int doStuff(float y){return 4;}
    Explanation
    The given code is creating two classes, Alpha and Beta. Beta is extending Alpha, indicating that Beta is a subclass of Alpha. The question asks which code, when inserted at line 8 in class Beta, will compile successfully.

    The correct answer is "protected int doStuff(float y){return 4;}, final int doStuff(float y){return 4;}".

    This answer is correct because it provides two valid methods that override the method "doStuff" from the superclass Alpha. The "protected" access modifier allows the method to be accessed within the package and by subclasses, while the "final" keyword indicates that the method cannot be overridden by any subclasses.

    Rate this question:

  • 15. 

    Class Silky extends Smooth{int x=5;int y=7;public static void main(String[] args){new Silky().go();}void go(){if(x>y & (Boolean)(this instanceof Silky))  System.out.print("a");if(Long.valueOf(4) instanceof Number) System.out.print("b");}}class Smooth{}what is the result?

    • A.

      A

    • B.

      B

    • C.

      Ab

    • D.

      Compilation fails

    • E.

      An exception is thrown at runtime

    Correct Answer
    B. B
    Explanation
    The code will print "b" as the result. This is because the first if statement evaluates to true since both conditions are true: x is greater than y, and the instance of the object is of type Silky. The second if statement also evaluates to true since Long.valueOf(4) is an instance of Number. Therefore, both if statements will execute and print "b".

    Rate this question:

  • 16. 

    Which are true?

    • A.

      Encapsulation limits the consequences of change.

    • B.

      Encapsulation makes it easier to reuse classes.

    • C.

      Encapsulation results in better testing and higher reliability.

    • D.

      Encapsulation means that methods are all public.

    • E.

      Encapsulation means that classes are members of packages.

    Correct Answer(s)
    A. Encapsulation limits the consequences of change.
    B. Encapsulation makes it easier to reuse classes.
    C. Encapsulation results in better testing and higher reliability.
    Explanation
    Encapsulation limits the consequences of change by hiding the internal implementation details of a class, allowing changes to be made to the class without affecting other parts of the program. This helps to maintain the integrity of the code and reduces the risk of introducing bugs or errors.

    Encapsulation makes it easier to reuse classes by bundling the data and methods that operate on the data within a single unit. This allows the class to be used as a black box, where the internal workings are hidden and only the interface is exposed. This simplifies the process of reusing the class in different parts of the program.

    Encapsulation results in better testing and higher reliability because it promotes modular design and reduces dependencies between different parts of the program. This makes it easier to test individual components in isolation, leading to more effective and efficient testing. Additionally, encapsulation helps to prevent unintended access or modification of data, improving the reliability of the code.

    Rate this question:

  • 17. 

    Class X{void go(){System.out.print("x");}}class Y extends X{void go(){System.out.print("y");}}class Z extends X{void go(){System.out.print("z");}}class Chrome1{public static void main(String[] args){X z=new Z();X y=new Y();Z y2=(Z)y;y.go();y2.go();}}what is the result?

    • A.

      Xxx

    • B.

      Xxz

    • C.

      Zyy

    • D.

      Zyz

    • E.

      An exception is thrown at runtime

    Correct Answer
    E. An exception is thrown at runtime
    Explanation
    The code creates an object of class Z and assigns it to a variable of type X. Then, it creates an object of class Y and assigns it to another variable of type X. Next, it tries to cast the Y object to type Z and assigns it to a variable of type Z. However, since the Y object is not actually an instance of Z, a ClassCastException is thrown at runtime. Therefore, the correct answer is "An exception is thrown at runtime".

    Rate this question:

  • 18. 

    Public class Felix{ protected long cat(){return 7L;}}class Oscar extends Felix{//insert code here} which method inserted ,will compile?

    • A.

      Private long cat(int x){return 7;}

    • B.

      Public long cat(){return 7;}

    • C.

      Long cat(){return 7;}

    • D.

      Protected int cat(int x){return 7;}

    • E.

      None of these

    Correct Answer
    C. Long cat(){return 7;}
    Explanation
    The method "long cat(){return 7;}" will compile because it has the same return type and access modifier as the method in the superclass Felix.

    Rate this question:

  • 19. 

    Which of the following are legal definitions for non-nested classes and interfaces?

    • A.

      Static public interface Foo{}

    • B.

      Abstract public class Foo{}

    • C.

      Protected interface Foo{}

    • D.

      Final abstract class Foo{}

    • E.

      Final public class Foo{}

    Correct Answer(s)
    B. Abstract public class Foo{}
    E. Final public class Foo{}
    Explanation
    The correct answer is "abstract public class Foo{}, final public class Foo{}".br/>The first option, "static public interface Foo{}", is incorrect because interfaces cannot be declared as static. The second option, "abstract public class Foo{}", is correct because classes can be declared as abstract and public. The third option, "protected interface Foo{}", is incorrect because interfaces cannot be declared with access modifiers other than public. The fourth option, "final abstract class Foo{}", is incorrect because a class cannot be both abstract and final. The fifth option, "final public class Foo{}", is correct because classes can be declared as final and public.

    Rate this question:

  • 20. 

    Public class Switch2{public static void main(String[] args){int y=0;for(int x=3;x>=0;x--){switch(x){case 3:y=y+100;case 2:y=y+10;case 1:break;case 0:y=y+1;}}System.out.println(y);}}what is the result?

    • A.

      120

    • B.

      121

    • C.

      122

    • D.

      123

    • E.

      Compilation fails

    Correct Answer
    B. 121
    Explanation
    The code starts with the variable y initialized to 0. Then, a for loop is executed 4 times, with x starting at 3 and decreasing by 1 in each iteration. Inside the loop, a switch statement is used to check the value of x. When x is 3, y is increased by 100. When x is 2, y is increased by 10. When x is 1, the break statement is encountered, causing the switch statement to exit. When x is 0, y is increased by 1. Therefore, the final value of y is 121.

    Rate this question:

  • 21. 

    Public static void main(String[] args){TreeSet<Number> tree=new TreeSet<Number>();tree.add(108);//insert here}which is inserted to compile and run

    • A.

      Tree.add(3.14);

    • B.

      Tree.add("42");

    • C.

      Tree.add(Integer.valueOf("-1"));

    • D.

      Tree.add(null);

    • E.

      Tree.add(0xCAFE)

    Correct Answer(s)
    C. Tree.add(Integer.valueOf("-1"));
    E. Tree.add(0xCAFE)
    Explanation
    The given code is trying to insert elements into a TreeSet of type Number. The TreeSet is a sorted set, which means it only allows elements that can be compared to each other.

    Out of the given options, "tree.add(Integer.valueOf("-1"))" and "tree.add(0xCAFE)" are the correct answers because they both insert valid Number objects into the TreeSet.

    The first option inserts an Integer object with a value of -1, which is a valid number. The second option inserts an Integer object with a hexadecimal value of 0xCAFE, which is also a valid number.

    The other options are incorrect because they try to insert a double value, a string, and a null value, which are not valid Number objects and cannot be compared in a TreeSet.

    Rate this question:

  • 22. 

    Calss Bulbs{ enum Turn{  ON("bright"),OFF("dark");}public staticmvoid main(String[] args){ System.out.println(Turn.ON);}}what is the result?

    • A.

      ON

    • B.

      Bright

    • C.

      Compilation fails

    • D.

      No output is produced

    • E.

      Exception

    Correct Answer
    C. Compilation fails
    Explanation
    The code provided will not compile because there is a typo in the main method declaration. "public staticmvoid" should be "public static void". As a result, the code will throw a compilation error.

    Rate this question:

  • 23. 

    Which is true?

    • A.

      It is not good practice to place assertions where you think execution should never reach.

    • B.

      It is sometimes appropriate to call getters and setters from assertions.

    • C.

      Use assertions to verify the arguments of private methods.

    • D.

      Assertions can be disabled for a particular class

    • E.

      Never throw an AssertionError explicitly

    Correct Answer(s)
    C. Use assertions to verify the arguments of private methods.
    D. Assertions can be disabled for a particular class
    Explanation
    Assertions are typically used to verify assumptions about the code during development and testing. By using assertions to verify the arguments of private methods, developers can ensure that the inputs to these methods are valid and meet the expected criteria. This helps catch potential bugs and errors early on. Additionally, assertions can be disabled for a particular class, which allows them to be selectively enabled or disabled based on the specific needs of the codebase or application. This flexibility can be useful in different testing scenarios or production environments.

    Rate this question:

  • 24. 

    Class Battery{static int x=1;public static void main(String[] args) throws Throwable{try{if(x==1)throw new Throwable();System.out.println("try");}catch(Exception e){System.out.println("exc");}finally{System.out.println("fin");}}}what is the result?

    • A.

      Try

    • B.

      Try fin

    • C.

      Exc fin

    • D.

      Fin then a runtime exception

    • E.

      Compilation fails

    Correct Answer
    D. Fin then a runtime exception
    Explanation
    The code first checks if the value of x is equal to 1. Since it is, it throws a new Throwable object. This causes the program to skip the "try" block and go directly to the "catch" block. The catch block prints "exc". After the catch block, the "finally" block is executed, which prints "fin". Since there is no code to handle the thrown Throwable object, a runtime exception occurs after the "finally" block is executed. Therefore, the result is "fin then a runtime exception".

    Rate this question:

  • 25. 

    Which of the following can be constructed using a String?

    • A.

      Java.io.File

    • B.

      Java.io.FileWriter

    • C.

      Java.io.PrintWriter

    • D.

      Java.io.FileReader

    • E.

      Java.io.BufferedWriter

    Correct Answer(s)
    A. Java.io.File
    B. Java.io.FileWriter
    D. Java.io.FileReader
    Explanation
    A String can be used to construct java.io.File, java.io.FileWriter, and java.io.FileReader objects. These classes are part of the Java I/O library and are used for file handling operations. A String can be passed as an argument to the constructors of these classes to specify the file path or name. The java.io.BufferedWriter and java.io.PrintWriter classes do not have constructors that accept a String as a parameter, so they cannot be constructed using a String.

    Rate this question:

  • 26. 

    String  sa ="ankur ";

    • A.

      Sa is instance variable .

    • B.

      Sa is object.

    • C.

      Sa is variable.

    • D.

      Sa is char type.

    • E.

      All of them.

    Correct Answer
    B. Sa is object.
    Explanation
    The given code declares a string variable named "sa" and assigns it the value "ankur". In Java, a string is an object of the String class. Therefore, "sa" is an object of the String class.

    Rate this question:

  • 27. 

    Constructor can have a return type as ?

    • A.

      Init.

    • B.

      Float.

    • C.

      Object.

    • D.

      String.

    • E.

      None of them.

    Correct Answer
    E. None of them.
    Explanation
    The correct answer is "none of them" because a constructor is a special method used to initialize objects of a class. It does not have a return type, as its purpose is to set up the initial state of an object rather than returning a value. Therefore, the return type cannot be specified for a constructor in any programming language.

    Rate this question:

  • 28. 

    Java having pointers as ?

    • A.

      Init type.

    • B.

      Float type.

    • C.

      String type.

    • D.

      Object type.

    • E.

      None of them.

    Correct Answer
    E. None of them.
    Explanation
    The correct answer is "none of them" because Java does not have pointers like other programming languages such as C or C++. Instead, Java uses references to objects, which are similar to pointers but with additional safety measures. In Java, variables of primitive types (such as int or float) store the actual values, while variables of object types (such as String or Object) store references to the memory location where the object is stored. Therefore, Java does not have pointers in the traditional sense.

    Rate this question:

  • 29. 

    Which type of inharitence  java  used ?

    • A.

      Multiple inheritance.

    • B.

      Single level.

    • C.

      Multi level.

    • D.

      Hibrid .

    • E.

      All of them.

    Correct Answer(s)
    B. Single level.
    C. Multi level.
    D. Hibrid .
    Explanation
    Java uses single level, multi level, and hybrid inheritance.

    Single level inheritance occurs when a class inherits from only one superclass. In Java, a class can extend only one superclass.

    Multi level inheritance occurs when a class inherits from a superclass, and that superclass itself inherits from another superclass. This creates a hierarchy of classes.

    Hybrid inheritance is a combination of different types of inheritance, such as single level and multi level inheritance, in a single program.

    Therefore, Java can use all three types of inheritance: single level, multi level, and hybrid.

    Rate this question:

  • 30. 

    Java is not ?

    • A.

      Plate form independent.

    • B.

      Roubust.

    • C.

      Secure.

    • D.

      Hierarical.

    • E.

      Structural.

    Correct Answer
    E. Structural.
    Explanation
    The term "structural" refers to the organization and arrangement of code in a program. In the context of Java, it means that the language provides features and constructs that allow developers to create well-organized and modular code. Java supports object-oriented programming principles, such as classes, objects, and inheritance, which enable developers to create a clear and logical structure for their code. This helps in improving code readability, maintainability, and reusability. Therefore, the correct answer is "structural" because Java provides mechanisms for structuring code effectively.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 15, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 20, 2009
    Quiz Created by
    Ankur_bit
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.