Results 1 to 5 of 5
  1. #1
    krashh205 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default Getting an error

    Hello friends I have a very fundamental doubt. You see, I just recently started taking java seriously. Currently I am into core java.

    I have a doubt regarding access modifiers- public, private, protected, default.

    Now what I have understood from reading the java textbook is that any class member will have one of these 4 access modifiers.

    Example for this Code-
    //Case1//
    =====

    try
    {
    BufferedImage originalImage = ImageIO.read(new File("C:\\Users\\PROTIK\\Desktop\\ReferenceProgram \\paper.jpg"));
    int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
    BufferedImage resizeImageJpg = resizeImage(originalImage, type);
    ImageIO.write(resizeImageJpg, "jpg", new File("C:\\Users\\PROTIK\\Desktop\\ReferenceProgram \\paper_resize.jpg"));
    }

    can also be written as
    //Case2//
    =====

    try
    {
    default BufferedImage originalImage = ImageIO.read(new File("C:\\Users\\PROTIK\\Desktop\\ReferenceProgram \\paper.jpg"));
    default int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
    default BufferedImage resizeImageJpg = resizeImage(originalImage, type);
    ImageIO.write(resizeImageJpg, "jpg", new File("C:\\Users\\PROTIK\\Desktop\\ReferenceProgram \\paper_resize.jpg"));
    }


    But whenever I am trying to write the code in Case 2 type, by mentioning the access modifiers of the class members I am getting a compile time error. The error is "illegal start of exception".

    Please somebody explain this to me??????

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

    Default

    Quote Originally Posted by krashh205 View Post
    try
    {
    default BufferedImage originalImage = ImageIO.read(new File("C:\\Users\\PROTIK\\Desktop\\ReferenceProgram \\paper.jpg"));
    default int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
    default BufferedImage resizeImageJpg = resizeImage(originalImage, type);
    ImageIO.write(resizeImageJpg, "jpg", new File("C:\\Users\\PROTIK\\Desktop\\ReferenceProgram \\paper_resize.jpg"));
    }
    'default' is a keyword used as a case selector in a switch statement. The default access specifier has no keyword, i.e. you can do:

    Java Code:
    private int foo;
    protected in bar;
    public int baz;
    int foobar;
    The last variable has a default (i.e. no explicit) access specifier.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    And access modifiers are for instance variables (fields) and methods of a class, not for local variables within methods.

    -Gary-

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Oh, and for classes themselves, of course.

    -Gary-

  5. #5
    krashh205 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 AM

Tags for this Thread

Posting Permissions

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