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

  • SEARCH
  • Home
  • 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 8082739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:13:10+00:00 2026-06-05T17:13:10+00:00

I am new to Java and trying to do a simple program to help

  • 0

I am new to Java and trying to do a simple program to help me further understand object-orientated programming.

I decided to do a phone program. However on line 5 of the following program where I’m trying to create an instance of a phone class I am getting the following error:

“No enclosing instance of type OOPTutorial is accessible. Must qualify the allocation with an enclosing instance of type OOPTutorial (e.g. x.new A() where x is an instance of OOPTutorial).”

Here is the program:

public class OOPTutorial {

    public static void main (String[] args){

        phone myMobile = new phone();           // <-- here's the error
        myMobile.powerOn();
        myMobile.inputNumber(353851234);
        myMobile.dial();

   }

   public class phone{
       boolean poweredOn = false;
       int currentDialingNumber;

       void powerOn(){
           poweredOn = true;
           System.out.println("Hello");
       }
       void powerOff(){
           poweredOn = false;
       System.out.println("Goodbye");
       }
       void inputNumber(int num){
       currentDialingNumber = num;
       }
       void dial(){
           System.out.print("Dialing: " + currentDialingNumber);
       }
   }
}
  • 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-06-05T17:13:11+00:00Added an answer on June 5, 2026 at 5:13 pm

    This may not make sense to you if you’re new to Java, but a instantiating a non-static inner class (phone) requires an instance of the enclosing class (OOPTutorial).

    In plain English, this roughly means that you either

    1. Can only do new phone() inside a OOPTutorial-method that is not marked as static, or

    2. you need to make phone a top level class (i.e. move it outside the scope of OOPTutorial), or

    3. you need to make the inner class phone as static (by putting static in front of the class declaration)

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

Sidebar

Related Questions

I'm new to java and trying to write a simple program using JDBC. It
I'm new to java and am trying to write a simple program that basicly
I am new to thread programming in Java. To understand threading I'm trying to
I'm really new to generics in Java. I'm trying to create a simple method
I am new to mutli-threading in java and trying to understand the keyword synchronization
I'm new to the programming world, and I am trying to do a simple
I am trying to program a very simple Mobile Application (J2ME) in java. The
I'm a new Java programmer, and I've been trying to setup a simple Swing
I am very new to JAVA. I have written simple program (in Linux -VIM
I'm new to graphics programming. I'm trying to create a program that allows you

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.