Home Java Java-get-example Java error incompatible types



Java error incompatible types
Posted on: November 3, 2008 at 12:00 AM
Java Error incompatible types occurred when a compiler found a variable and expression whose data type is not compatible to perform an operation on them.

Java error incompatible types

     

Java Error incompatible types occurred when a compiler found a variable and expression whose data type is not compatible to perform an operation on them.

Understand with an Example

In this Tutorial we want to describe you a code that help you in understanding the java error incompatible type. For this we have a class name Incompatobletype.Inside the main method we declare a variable name roll num  and sec int and char  data type. Checklist condition is used to evaluate the expression. The assignment operator = is used to show you an incompatible type error in java rather than using = = in assignment operator. The Java Compiler show an error in the assignment operator printed by System.out.println.

 

Incompatitabletype.java


public class  >Icompatobletype {

  public static void main(String[] args) {

  int rollnum = 76;
  char sec;
  if (rollnum = 90) {
  sec = 'A';
  else {
  sec = 'B';
  }
  System.out.println("Section with this rollno is:  = " + sec);
  }
}

Output

Compiling source file to /home/girish/NetBeansProjects/errors/build/classes
/home/girish/NetBeansProjects/errors/src/Icompatobletype.java:8: incompatible types
found : int
required: boolean
  if (rollnum = 90) {
error
BUILD FAILED (total time: seconds)

To resolve this error give if (rollnum = =90)instead of if (rollnum = 90)

Download code

Related Tags for Java error incompatible types:
javacerrorcomcompilerormdataformiotypesvariabletypecompileexpressionpilriaoperaformpitoexpressssieilnotvarpeinnormmososjoperationesempiwhensessatratioincispresspreandarccxpvassrithavabablatiprndonomo


More Tutorials from this section

Ask Questions?    Discuss: Java error incompatible types   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.