Java Programming Quiz

AwedExuberance avatar
AwedExuberance
·
·
Download

Start Quiz

Study Flashcards

30 Questions

Which keyword is used to implement an interface in Java?

implements

What is the default accessibility of variables in an interface?

public

Can a class implement multiple interfaces in Java?

Yes

Can an interface implement another interface in Java?

No

What is the purpose of method overriding in Java?

To reduce unwanted code

What is an abstract class in Java?

A class that contains only abstract methods

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

Object-oriented programming

What is a class in Java?

A template that has certain attributes

What is an object in Java?

An instance of a class

What is the purpose of OOPs in Java?

To make the program reusable, easier to modify and debug

What does the 'private' keyword indicate in Java?

The method can only be accessed by the class itself

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);

600

Which type of constructor is used to initialize an object with 0 or null values?

Default constructor

What is the purpose of constructors in Java?

To initialize objects

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

void

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

$amount = principal + (principal * rate * time) / 100$

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

To provide security

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

To display all the members of the class

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

Declaring class attributes as private and getter and setter methods as public

What is the purpose of using getter and setter methods in Java?

To get and set the values of private data members

Which keyword is used to implement inheritance in Java?

extends

In the given code, what is the output of the following statement: 'System.out.println(S.getNoOfItems());' ?

153

What is the purpose of using inheritance in Java?

To increase the reusability of code

What is the value of 'b' in the output of the following statement: 'objMS.get();' ?

20

Which type of inheritance is demonstrated in the example code?

Hierarchical inheritance

What is the purpose of abstract classes in Java?

To hide complex background details

What happens if a subclass tries to inherit private data members from its parent class?

The subclass cannot inherit the private data members

What is the difference between runtime polymorphism and compile-time polymorphism?

Runtime polymorphism occurs during inheritance, while compile-time polymorphism occurs during method/function overriding

What is the purpose of the @Override annotation in Java?

To indicate that a method is overridden

What is the result of executing the code in the example?

All of the above

Test your knowledge on Java programming with this quiz!

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser