Java OOPS (medium)

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which keyword is used to implement an interface in Java?

  • class
  • extends
  • implements (correct)
  • abstract

Which type of methods can an abstract class contain?

  • Only abstract methods
  • Only regular methods
  • Both abstract and regular methods (correct)
  • No methods

What is the default access modifier for variables in an interface?

  • public (correct)
  • final
  • protected
  • private

Can a class implement multiple interfaces in Java?

<p>Yes (C)</p> Signup and view all the answers

Can an interface implement another interface in Java?

<p>No (A)</p> Signup and view all the answers

Can objects be created from interfaces in Java?

<p>No (A)</p> Signup and view all the answers

Which type of constructor is used to initialize objects with default values?

<p>Default constructor (B)</p> Signup and view all the answers

Which constructor is used to initialize an object using the values of another object?

<p>Copy constructor (A)</p> Signup and view all the answers

What is the return type of the addAmount() method in the Bank class?

<p>void (A)</p> Signup and view all the answers

What is the access modifier of the displayData() method in the Bank class?

<p>public (A)</p> Signup and view all the answers

What is the formula to calculate the amount for a particular principal amount, rate of interest, and time?

<p>$amount = principal * rate / time$ (C)</p> Signup and view all the answers

Why are the data members of the Bank class declared as private?

<p>To provide security (C)</p> Signup and view all the answers

Which programming paradigm focuses more on the data and related methods rather than procedures?

<p>Object-oriented programming (B)</p> Signup and view all the answers

What is a template that has certain attributes in Java?

<p>Class (B)</p> Signup and view all the answers

What is an instance of a class in Java?

<p>Object (D)</p> Signup and view all the answers

What is the access modifier used for the 'name' variable in the 'Bank' class?

<p>private (B)</p> Signup and view all the answers

What is the purpose of the 'deposit' method in the 'Bank' class?

<p>To update the balance (D)</p> Signup and view all the answers

What is the output of the following code?

Bank obj = new Bank();
obj.getData();
obj.deposit(1500);
float amount = obj.calculateAmount(300, 4, 2);
System.out.println(amount);

<p>1800 (C)</p> Signup and view all the answers

Which type of inheritance is demonstrated in the given example: A->B->C, where A, B, C are classes and B is derived from A and C is derived from B?

<p>Multi-level inheritance (C)</p> Signup and view all the answers

Which type of polymorphism takes place during method/function overloading?

<p>Compile-time polymorphism (B)</p> Signup and view all the answers

What does it mean for a class to be declared as abstract?

<p>Objects cannot be created from the class (C)</p> Signup and view all the answers

What is the purpose of the 'abstract' keyword in Java?

<p>To define a class as abstract (A)</p> Signup and view all the answers

What happens when an abstract method is declared in a class?

<p>The method must have an empty body (A)</p> Signup and view all the answers

What annotation can be used to indicate that a method is being overridden?

<p>@Override (B)</p> Signup and view all the answers

Which of the following is the purpose of encapsulation in Java?

<p>To achieve data hiding (A)</p> Signup and view all the answers

Which of the following is an example of encapsulation in Java?

<p>Declaring private class attributes and using getter and setter methods (B)</p> Signup and view all the answers

What is the purpose of inheritance in Java?

<p>To increase reusability of code (C)</p> Signup and view all the answers

Which keyword is used to inherit properties from a parent class in Java?

<p>extends (B)</p> Signup and view all the answers

What is the purpose of getter and setter methods in encapsulation?

<p>To increase control of class and attributes (D)</p> Signup and view all the answers

Which of the following is an example of inheritance in Java?

<p>Inheriting properties of a parent class (D)</p> Signup and view all the answers

Flashcards are hidden until you start studying

More Like This

Abstract Classes and Interfaces Flashcards
17 questions
Abstract Classes and Interfaces
15 questions

Abstract Classes and Interfaces

ContrastyEnlightenment3836 avatar
ContrastyEnlightenment3836
Use Quizgecko on...
Browser
Browser