Results 1 to 4 of 4
  1. #1
    Roselicious is offline Member
    Join Date
    Apr 2010
    Posts
    24
    Rep Power
    0

    Default Primitive data type and class

    Which is the primitive data type and which is the class?

    Java Code:
    int[] scores = {85,67,72,40};

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,363
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Roselicious View Post
    Which is the primitive data type and which is the class?

    Java Code:
    int[] scores = {85,67,72,40};
    That is just an array of ints; ints are primitives and arrays are objects but they are a bit special: you can't extend them and they don't have any methods.

    kind regards,

    Jos

  3. #3
    Roselicious is offline Member
    Join Date
    Apr 2010
    Posts
    24
    Rep Power
    0

    Default

    oh ok thanks . I know the output is First score is 85. But how to I explain how I got the output

    Java Code:
    public class ClassB
    {
    public static void main(String[] args)
    {
    int[] scores = {85,67,72,40};
    change(scores[0]);
    System.out.println("First score is " + score[0]);
    }
    public static void change(int n)
    {
    n = 100;
    }
    }

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,363
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Roselicious View Post
    oh ok thanks . I know the output is First score is 85. But how to I explain how I got the output

    Java Code:
    public class ClassB
    {
    public static void main(String[] args)
    {
    int[] scores = {85,67,72,40};
    change(scores[0]);
    System.out.println("First score is " + score[0]);
    }
    public static void change(int n)
    {
    n = 100;
    }
    }
    That's just Java's call by value mechanism, it has nothing to do with objects or primitives.

    kind regards,

    Jos

Similar Threads

  1. JNI accessing non primitive data type
    By H_P in forum Advanced Java
    Replies: 1
    Last Post: 04-14-2010, 05:43 AM
  2. declare class data member as an inteface type
    By everurz in forum Advanced Java
    Replies: 3
    Last Post: 12-21-2009, 01:04 PM
  3. primitive Data types
    By Manfizy in forum New To Java
    Replies: 2
    Last Post: 07-07-2009, 08:29 PM
  4. Primitive data types of Java
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-28-2008, 07:29 PM
  5. Uisng primitive type values as keys for Hashtable
    By ravian in forum New To Java
    Replies: 3
    Last Post: 11-21-2007, 10:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •