• Study Materials
    • InfyTQ Archive
    • Infosys Archive
    • TCS Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Tutorials
    • Node.js Tutorial
    • Express.js Tutorial
    • Python Tutorial
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
    • Java Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials
      • InfyTQ Archive
      • Infosys Archive
      • TCS Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Tutorials
      • Node.js Tutorial
      • Express.js Tutorial
      • Python Tutorial
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
      • Java Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials
    • InfyTQ Archive
    • Infosys Archive
    • TCS Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Tutorials
    • Node.js Tutorial
    • Express.js Tutorial
    • Python Tutorial
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
    • Java Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements

Java MCQs Output Questions and Code Snippets

  • December 21, 2021
  • CODE OF GEEKS
  • 1


Q. Find the output

class Demo {
    public static void main(String args[]) {
      for (int i =0; i <3; i++) {
        switch(i) {
        case 0: break;
        case 1: System.out.print("one ");
        case 2: System.out.print("two ");
        case 3: System.out.print("three ");
        }
        }
        System.out.println("done");
        }
}

A. done
B. one two three done
C. one two three two three done
D. one two three one three one two done

View Answer

 

Ans. C

Q. Find the output

class Demo {
    public static void main(String args[]) {
        int index = 0;
        boolean flag = true;
        boolean a = false, b;
        b = (flag | ((index++) == 0));
        b = (a | ((index += 2) > 0));
        System.out.println(index);
    }
}

A. 0
B. 1
C. 2
D. 3

View Answer

 

Ans. D


Q. Find the output

class Demo {
    public static void main() {
        int odd = 1;
        if (odd) {
            System.out.println("odd");
        } else {
            System.out.println("even");
        }
    }
}

A. odd
B. even
C. odd even
D. Error

View Answer

 

Ans. D

Q. Find the output

class Demo {
    public static void main(String [] args) {
        char ch = 'G';
        int m = ch;
        m=m+5;
        System.out.println(m + " " + ch);
    }
}

A. 5 G
B. 76 G
C. 71 G
D. Error : Can’t append int to string

View Answer

 

Ans. B

Q. Find the output

class Demo {
    public static void main(String args[]) {
      for (int i =0.0; i <3.0; i++) {
        switch(i) {
        case 0: break;
        case 1: System.out.print("one ");
        case 2: System.out.print("two ");
        case 3: System.out.print("three ");
        }
        }
        System.out.println("done");
        }
}

A. done
B. one two three done
C. Runtime Error
D. one two three one three one two done

View Answer

 

Ans. C


Pages: 1 2 3 4 5 6 7 8 9
  • Previous InfyTQ Certification Exam 2022-2023 | Eligibility Criteria | Helpful Study Materials
  • Next Difference between function and method in Python with example

1 comment on “Java MCQs Output Questions and Code Snippets”

  1. Ashok Mule says:
    August 14, 2023 at 4:08 pm

    class Teacher{
    String name;
    Teacher(){
    System.out.println(“In Teacher class”);
    }
    }
    class Student extends Teacher{
    Student(){
    System.out.println(“In Student class”);
    }
    int id;
    public static void main(String a[]){
    Student ob=new Student(); //Line 1
    ob.name=”abcde”; //Line 2
    ob.id=12345;}
    }

    Correct output should be: In Teacher class In Student class

    Please modify option B

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Learning Python

python tutorials

InfyTQ Previous Year Questions 2023

  • InfyTQ 2023 Overview
  • InfyTQ Previous Year Coding Questions
  • InfyTQ Previous Year Python Questions
  • InfyTQ Previous Year Java Questions
  • InfyTQ Previous Year DBMS Questions
  • 100+ Python MCQs for InfyTQ
  • Java MCQs for InfyTQ

Study Materials : Company Wise

CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions
Refund Policy
Contact us

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Tutorials

Python
Node.js
Express.js
Golang

Recent Posts

Strings in Go and its basic operations
  • August 11, 2023
Introduction to Functions in Go programming
  • August 11, 2023

Copyright @ CODE OF GEEKS. All Rights Reserved.