50 Java Language MCQs With Answers - GeeksforGeeks

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

DSA Tutorials ML & Data Science Web Development Practice Sign In

Trending Now Data Structures Algorithms Foundational Courses Data Science Practice Problem Python Machine Learning JavaScript Java C C++ ReactJS NodeJS Web De

Explore Our Geeks Community


Recently Published
Interview Preparation 50 Java Language MCQs with Answers
Read Discuss Courses
Practice @Geeksforgeeks

Data Structures
Question 1
Accessibility in UI/UX Design: How to S
A Complete Guide Complet
Algorithms
Output of following Java Program?

Programming Languages Read


class Base {
public void show() {
System.out.println("Base::show() called");
Web Technologies
}
}
Computer Science Subjects
class Derived extends Base {
public void show() {
Data Science & ML System.out.println("Derived::show() called");
}
}
Tutorial Library
public
We use cookies to ensure you have the best browsing class
experience Main
on our { By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
website. Got It !
public static void main(String[] ▲
args) {
GATE CS Base b = new Derived();;
b.show();
}
}

Run on IDE

Derived::show() called
Base::show() called

Java Inheritance 50 Java Language MCQs with Answers

Discuss it

Question 2

What is the use of final keyword in Java?

When a class is made final, a subclass of it can not be created.

When a method is final, it can not be overridden.

When a variable is final, it can be assigned value only once.

All of the above

Java nal keyword 50 Java Language MCQs with Answers

Discuss it

Question 3

class Base {
final public void show() {
System.out.println("Base::show() called");
}
}

class Derived extends Base {


public void show() {
System.out.println("Derived::show() called");
}
}

class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}

Run on IDE

Base::show() called
Derived::show() called
Compiler Error
Runtime Error

Java Inheritance 50 Java Language MCQs with Answers

Discuss it

Question 4

Java

class Base {
public static void show() {
System.out.println("Base::show() called");
}
}

class Derived extends Base {


public static void show() {
System.out.println("Derived::show() called");
}
}

class Main {
public static void main(String[] args) {
Base b = new Derived();
b.show();
}
}

Run on IDE

Base::show() called
Derived::show() called
Compiler Error

Java Inheritance 50 Java Language MCQs with Answers

Discuss it

Question 5

Which of the following is FALSE about arrays in Java?

A java array is always an object

Length of array can be changed after creation of array

Arrays in Java are always allocated on heap

Java Arrays 50 Java Language MCQs with Answers

Discuss it

Question 6

Predict the output?

package main;
class T {
int t = 20;
}
class Main {
public static void main(String args[]) {
T t1 = new T();
System.out.println(t1.t);
}
}

Run on IDE

20
0
Compiler Error

Java Constructors 50 Java Language MCQs with Answers

Discuss it

Question 7

Predict the output of following Java program

class T {
int t = 20;
T() {
t = 40;
}
}
class Main {
public static void main(String args[]) {
T t1 = new T();
System.out.println(t1.t);
}
}

Run on IDE

20
40
Compiler Error

Java Constructors 50 Java Language MCQs with Answers

Discuss it

Question 8

Which of the following is FALSE about abstract classes in Java

If we derive an abstract class and do not implement all the abstract methods, then
the derived class should also be marked as abstract using 'abstract' keyword
Abstract classes can have constructors
A class can be made abstract without any abstract method
A class can inherit from multiple abstract classes.

Java Abstract Class and Interface 50 Java Language MCQs with Answers

Discuss it

Question 9

Predict the output?

// file name: Main.java


public class Main {
public static void main(String args[]) {
int arr[] = {10, 20, 30, 40, 50};
for(int i=0; i < arr.length; i++)
{
System.out.print(" " + arr[i]);
}
}
}

Run on IDE

10 20 30 40 50
Compiler Error
10 20 30 40

Java Arrays 50 Java Language MCQs with Answers

Discuss it

Question 10

Which of the following is true about interfaces in java.

1) An interface can contain following type of members.


....public, static, final fields (i.e., constants)
....default and static methods with bodies

2) An instance of interface can be created.

3) A class can implement multiple interfaces.

4) Many classes can implement the same interface.

1, 3 and 4

1, 2 and 4

2, 3 and 4

1, 2, 3 and 4

Java Abstract Class and Interface 50 Java Language MCQs with Answers

Discuss it

There are 50 questions to complete.

Last Updated : 23 Feb, 2022

Similar Reads
Python MCQ (Multiple Choice
Ruby Programming Language
Questions) with Answers

Perl Programming Language R Programming Language Free Course

Java.lang package in Java Java.util Package in Java

Free Java Course Online for Beginners


Java.io Package in Java
- Java Programming

Java Multiple Choice Questions Fork Java Contest Certificates

Company Explore Languages DSA Data Science & HTML & CSS

About Us Job-A-Thon Hiring Python Data Structures ML HTML


A-143, 9th Floor, Sovereign Corporate
Tower, Sector-136, Noida, Uttar Pradesh - Challenge
Legal Java Algorithms Data Science With CSS
201305
Careers Hack-A-Thon C++ DSA for Beginners Python Bootstrap

In Media GfG Weekly Contest PHP Basic DSA Problems Data Science For Tailwind CSS
O line Classes Beginner
Contact Us GoLang DSA Roadmap SASS
(Delhi/NCR) Machine Learning
Advertise with us SQL Top 100 DSA LESS
DSA in JAVA/C++ Tutorial
GFG Corporate R Language Interview Problems Web Design
Master System ML Maths
Solution Android Tutorial DSA Roadmap by
Design Sandeep Jain Data Visualisation
Placement Training
Master CP Tutorial
Program All Cheat Sheets
GeeksforGeeks Pandas Tutorial
Apply for Mentor
Videos NumPy Tutorial

NLP Tutorial

Deep Learning
Tutorial

Python Computer DevOps Competitive System Design JavaScript

Python Science Git Programming What is System TypeScript


Programming GATE CS Notes AWS Top DS or Algo for Design ReactJS
Examples CP Monolithic and
Operating Systems Docker NextJS
Django Tutorial Top 50 Tree Distributed SD
Computer Network Kubernetes AngularJS
Python Projects Top 50 Graph High Level Design or
Database Azure NodeJS
Python Tkinter HLD
Management GCP Top 50 Array Express.js
Web Scraping System Low Level Design or
DevOps Roadmap Top 50 String Lodash
LLD
OpenCV Python So ware Top 50 DP
Crack System Design Web Browser
Tutorial Engineering
Top 15 Websites for Round
Python Interview Digital Logic Design CP
Question System Design
Engineering Maths
Interview Questions

Grokking Modern
System Design

NCERT School Subjects Commerce Management & UPSC Study SSC/ BANKING
Solutions Mathematics Accountancy Finance Material SSC CGL Syllabus

Class 12 Physics Business Studies Management Polity Notes SBI PO Syllabus

Class 11 Chemistry Indian Economics HR Managament Geography Notes SBI Clerk Syllabus

Class 10 Biology Macroeconomics Income Tax History Notes IBPS PO Syllabus

Class 9 Social Science Microeconimics Finance Science and IBPS Clerk Syllabus

Class 8 English Grammar Statistics for Economics Technology Notes SSC CGL Practice

Complete Study Economics Economy Notes Papers

Material Ethics Notes

Previous Year Papers

Colleges Companies Preparation Exams More Tutorials Write & Earn

Indian Colleges IT Companies Corner JEE Mains So ware Write an Article


Admission & So ware Company Wise JEE Advanced Development Improve an Article
Campus Experiences Development Preparation So ware Testing
GATE CS Pick Topics to Write
Top Engineering Companies Preparation for SDE Product
NEET Share your
Colleges Artificial Management
Experienced UGC NET Experiences
Top BCA Colleges Intelligence(AI) Interviews SAP Internships
Top MBA Colleges Companies
Internship SEO
Top Architecture CyberSecurity Interviews Linux
College Companies
Competitive Excel
Choose College For Service Based Programming
Graduation Companies
Aptitude
Product Based Preparation
Companies
Puzzles
PSUs for CS
Engineers

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

You might also like