Java quiz questions

Java interview questions

  • 1.

    The process of putting methods and data members in a single class is called __________.

    1. encapsulation

    2. inheritance

    3. interface

    4. abstraction

    Answer
  • 2.

    Which one does not exist in the block of a class?

    1. data member

    2. mehtod

    3. class

    4. package

    Answer
  • 3.

    When you create class, what is the most important thing that you have to think about?

    1. data members and methods

    2. setters and getters

    3. constructors

    4. access modifiers

    Answer
  • 4.

    Which one is the correct syntax to create an object from the “Books” class?

    1. Book myBook = new Book( );

    2. Books myBook = Books( );

    3. Books myBook = new Books( );

    4. Books myBook = new books( );

    Answer
  • 5.

    Which one is the correct syntax to create a class?

    1. public Class MyClass { }

    2. public class MyClass { }

    3. private class MyClass { }

    4. Class MyClass { }

    Answer
  • 6.

    The keyword “ public “ and “ private “ are called ____________.

    1. delimiter

    2. access specifier

    3. class protector

    4. instance variable

    Answer
  • 7.

    How many objects that you can create from a class Users?

    1. one

    2. two

    3. three

    4. unlimited

    Answer
  • 8.

    The term ________ refers to an actual instance of a class.

    1. method

    2. object

    3. class

    4. data member

    Answer
  • 9.

    If you declare an instance variable without any access modifier, what is the default access modifier?

    1. public

    2. private

    3. package-private

    4. protected

    Answer
  • 10.

    Which one is the variable that cannot be declared with any access modifier?

    1. Instance variable

    2. Class variable

    3. Local variable

    4. Non-static variable

    Answer
  • 11.

    Generally, getter methods always have parameters.

    1. True

    2. False

    Answer
  • 12.

    Generally, setter methods always have return type “ void “.

    1. True

    2. False

    Answer
  • 13.

    Every class definition must have data member, otherwise it will not work.

    1. True

    2. False

    Answer
  • 14.

    In the same package, you cannot have two classes with the same name.

    1. True

    2. False

    Answer
  • 15.

    In the same class, you cannot have two objects with the same name.

    1. True

    2. False

    Answer
  • 16.

    The “ this “ keyword can be used to represent the current class.

    1. True

    2. False

    Answer
  • 17.

    The “ new “ keyword is used to instantiate a new object from a class.

    1. True

    2. False

    Answer
  • 18.

    If you create a method with public access modifier, it means that you can access it anywhere.

    1. True

    2. False

    Answer
  • 19.

    Setter is a method that is used to get value from an instance variable.

    1. True

    2. False

    Answer
  • 20.

    Every instance variable should be declared with private access specifier.

    1. True

    2. False

    Answer

© 2017 QuizBucket.org