• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

63
Views
Why there is no compilation error when I am using different data types for switch expression and case value in this case
public class Conditionsif {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int day=1;
        switch(day){
        case '1':
            System.out.println("Monday");
            break;
        
        }
        
    }

}

There is no compilation error in above though switch expression is integer data type and case value is character

4 months ago ·

Santiago Trujillo

1 answers
Answer question

0

Its because of implicit casting ascii value of a is 97

 switch(97){
           case 'a': System.out.println("a"); break;
           case 'b': System.out.println("b"); break;
           case 'c': System.out.println("c"); break;
 }
4 months ago · Santiago Trujillo Report
Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.