java-basics-1007 / java-hello

0 stars 0 forks source link

Assignment 24-06-2024 #3

Open nginx500 opened 5 months ago

nginx500 commented 5 months ago

For each question write your answer below.

  1. What are the primitive types in java. (byte, charm short, int , long, float, double, boolean)
  2. What is the range of values that a byte can hold. (-128 to 127)
  3. Give example of loosy conversion using int and byte data type. (short s = (short) 19000;)
  4. Define a custom type or class using int id, String name
    public class Employee {
    public int id;
    public String name;
    }
  5. What is the respective wrapper type of int. (Integer)
  6. How many times static block of a class executes and when? (once when the class gets loaded into JVM)

Compile below code using notepad and fix it if any issue exists. Then show output.


public class Solution{
  public static void main(String[] args){
   int x;
  System.out.println(x);
  }
}
nginx500 commented 5 months ago

@avnishhero7 submit the assignment in next 24 hours. I will give next assignment post that.

avnishhero7 commented 5 months ago

1.) Byte, char, int, long, float, short 2.) A byte can hold 8 bits 3.) An int being converted to a short 4.) public class Custom{ public static void main(String[] args){ str x = "x"; } } 5.) integer 6.) Once, when the code compiles. image