Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-11-2009, 10:18 AM
Member
 
Join Date: Dec 2008
Posts: 98
Rep Power: 0
itaipee is on a distinguished road
Default dont let me create simple class
hi everyone , this is the code ( hole class , just for testing) :
Testit is the name of the class with the main method
Testit1 is sub-class.

The problem - in the line "Testit1 st1=new Testit1(66);" there is the following error -
Quote:
No enclosing instance of type Testit is accessible. Must qualify the allocation with an
enclosing instance of type Testit (e.g. x.new A() where x is an instance of Testit).
How to fix it? I dont quite understand even what the problem is

Code:
public class Testit {

	public class Testit1
	{
		public int a1;
		public boolean b1;
		public Testit1(int a)
		{
			this.a1=a;
			b1=false;
		}	
	};
		public static void main(String[] args) {
		
		int b=1;
		Testit1 st1=new Testit1(66);
		if (st1==null)
			System.out.println("sorry, Testit1 is null");
		else
			System.out.println("Testit1 exist and the int is "+st1.a1);

	}
		

}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-11-2009, 10:42 AM
Darryl.Burke's Avatar
Senior Member
 
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 736
Rep Power: 2
Darryl.Burke is on a distinguished road
Default
First of all, Testit1 is not a subclass, it's an inner class. What did you start out to do, make a subclass or make an inner class?

db
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-11-2009, 11:01 AM
Member
 
Join Date: Dec 2008
Posts: 98
Rep Power: 0
itaipee is on a distinguished road
Default
Quote:
Testit1 is not a subclass, it's an inner class.
You right - my mistake

Any way, as you can see - it is not a real program. just for me to understand the how classes and arguments and references flow in methods.

so why
Quote:
Testit1 st1=new Testit1(66);
does not complie?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-11-2009, 11:02 AM
Member
 
Join Date: Dec 2008
Posts: 98
Rep Power: 0
itaipee is on a distinguished road
Default
by the way - Testit1 in my code is inner class, makes sense.

so what is sub-class?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-11-2009, 12:01 PM
Darryl.Burke's Avatar
Senior Member
 
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 736
Rep Power: 2
Darryl.Burke is on a distinguished road
Default
A subclass is one that extends a class.
Code:
class SuperClass {}

class SubClass extends SuperClass {}
Here's a good learning resource:
Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)

db
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-11-2009, 12:07 PM
Darryl.Burke's Avatar
Senior Member
 
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 736
Rep Power: 2
Darryl.Burke is on a distinguished road
Default
And, if you're prepared to devote time to understanding inner classes and enclosing instances:
Classes

Considering the present stage of your learning Java (as I perceive it) you might want to just read through that page and come back to it later. You could bookmark this:
The Java Language Specification, Third Edition - TOC

db
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How Can I Create a Simple Grid with a GridLayout? geeeeky.girl AWT / Swing 7 01-07-2009 04:31 AM
How to create main class link to another two class? pearllymary78 New To Java 6 07-17-2008 12:02 AM
8 questions I dont understand while studying for SCJP shankhas Professional Certification 2 06-16-2008 05:45 AM
How to create a simple deadlock Java Tip java.lang 0 04-09-2008 07:36 PM
Hello! and I need help. I dont know were to start Fall0ut New To Java 8 01-16-2008 12:59 AM


All times are GMT +2. The time now is 08:34 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org