Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 756997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:18:39+00:00 2026-05-14T15:18:39+00:00

Big class contains Format-interfcase and Format-class. The Format-class contains the methods and the interface

  • 0

Big class contains Format-interfcase and Format-class. The Format-class contains the methods and the interface has the values of the fields. I could have the fields in the class Format but the goal is with Interface. So do I just create dummy-vars to get the errors away, design issue or something ELSE?

KEY: Declaration VS Initialisation

  1. Explain by the terms, why you have to init in interface.
  2. What is the logic behind it?
  3. To which kind of problems it leads the use of interface?

Sample Code having the init-interface-problem

import java.util.*;
import java.io.*;

public class FormatBig
{

        private static class Format implements Format
        {
                private static long getSize(File f){return f.length();}
                private static long getTime(File f){return f.lastModified();}
                private static boolean isFile(File f){if(f.isFile()){return true;}}
                private static boolean isBinary(File f){return Match.isBinary(f);}
                private static char getType(File f){return Match.getTypes(f);}
                private static String getPath(File f){return getNoErrPath(f);}
                //Java API: isHidden, --- SYSTEM DEPENDED: toURI, toURL


                Format(File f)
                {
                  // PUZZLE 0: would Stack<Object> be easier?
                        size=getSize(f);
                        time=getTime(f);
                        isfile=isFile(f);
                        isBinary=isBinary(f);
                        type=getType(f);
                        path=getPath(f);

                    //PUZZLE 1: how can simplify the assignment?
                        values.push(size);
                        values.push(time);
                        values.push(isfile);
                        values.push(isBinary);
                        values.push(type);
                        values.push(path);
                }
        }

        public static String getNoErrPath(File f)
        {
                try{return f.getCanonicalPath();
                }catch(Exception e){e.printStackTrace();}
        }

        public static final interface Format
        {
                //ERR: IT REQUIRES "="
                public long size;
                public long time;
                public boolean isFile=true;   //ERROR goes away if I initialise wit DUMMY
                public boolean isBinary;
                public char type;
                public String path;
                Stack<Object> values=new Stack<Object>();
        }

        public static void main(String[] args)
        {
                Format fm=new Format(new File("."));
                for(Object o:values){System.out.println(o);}
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:18:39+00:00Added an answer on May 14, 2026 at 3:18 pm

    @Tom has answered your direct question. Basically, you cannot declare instance-level attributes (or class-level variables) in an interface. Instance level attributes must be declared in a class.

    If you want multiple classes to share the same attribute declarations, you could put them into an abstract superclass. But best practice is to declare the attributes as private and access them via getters and setters.

    There are a couple of other problems with your code:

    • You cannot declare a class and an interface with the same name in the same namespace. You have a class called Format that implements an interface called Format, both declared in the namespace of the FormatBig. And even if you could (e.g. because they were declared in different namespaces), this is bad practice. Give the class and interface distinct names.

    • You should use nested classes sparingly. It looks to me like you might have nested the Format class and interface inside FormatBig as a convenience so that you only have to edit and compile one file. That is lazy. Alternatively, if you are doing it to organize your code, learn how to use Java packages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 453k
  • Answers 453k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer a2ensite is for Apache2 hence the a2. I'm sure you… May 15, 2026 at 9:27 pm
  • Editorial Team
    Editorial Team added an answer You define a function called :. Inside this function you… May 15, 2026 at 9:27 pm
  • Editorial Team
    Editorial Team added an answer I'm not sure which application server is being referred to… May 15, 2026 at 9:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.