1 What are primitive data types in Java Is String a primitiv
1. What are primitive data types in Java? Is String a primitive data type? Why we can’t use == to compare the values of two strings?
2. How to declare and use arrays of objects? What are the benefits of using arrays of objects?
3. Take a look at code blow, why we will get some errors from JAVA compiler?
public class cp3myclass {
public static void test1(){}
public void test2(){}
private static void test3(){}
private void test4(){}
}
public class cp3staticmethod {
public static void main(String[] args) {
cp3myclass t1 = new cp3myclass();
t1.test1();
cp3myclass.test1();
t1.test2();
cp3myclass.test2();
t1.test3();
cp3myclass.test3();
t1.test4();
cp3myclass.test4();
}}
Solution
Answer:-1
Primitive datatypes are basic data type and those are predefined by the Java language. In java eight primitive data type are: byte, short, int, Boolean, long, float, double, char
String is not a primitive data type in Java. (In java only eight (byte, short, int, Boolean, long, float, double, char) primitive data type)
we are not using == to compare the values of two strings because it compares references equality not value of string.
Answer:-2
Student[] student_array = new Student[10]; // declare array object to store student avg_marks
student_arrary[i].avg_marks(); // used array object to call avg_marks funcation
An array for objects of a class A can store objects of a class B if class B extends class A.
So by creating an array of object type you can store references of any class objects.
Answer :-3
We are getting some of error from java compiler: -
We cannot make a static reference to the non-static method.
Cannot make a static reference to the non-static method test2() from the type cp3myclass
Private method cannot access outside the class
The method test3() is the private type in cp3myclass so it is not visible
The method test4() is the private type in cp3myclass so it is not visible
---------------------------------------------------------------------------------------------------
If you have any query, please feel free to ask
Thanks a lot

