I have a class, let's call it LineGraph, that renders a line graph. I need to subclass it, but the derived class is only used in one place and is coupled ... |
Reading through "Thinking in Java" i stuck in ex:6 of Inner Classes chapter.
Exercise 6: (2) Create an interface with at least one method, in its own package. Create a
class ... |
I have a class CircularBuffer which extends AbstractList.
I have a second class ExponentialUnrolledLinkedList which has an inner class Node which extends CircularBuffer.
I can access some protected members of instances of Node ... |
A
|_A1
| |_parent.java
|_child.java
does parent.java inherits child.java in any possible way?
here A and A1 are packages or directories
|
This method is inside JFrame object, how can I pass that JFrame object as an argument to the method in its inner class??
My code is:
The comment explains what I am ... |
Java Q: I can't access a public variable in my parent's class' inner class called foo. Why? setup is next(pseudo coded for brevity):
public class PageObject
{
...
|
How can I make something like this work:
class Outer {
int some_member;
abstract class InnerBase {
abstract void method();
}
}
class OuterExtendsInner extends Outer.InnerBase {
...
|
|
Say I have the following:
public class A {
//stuff
public class B implements I {}
}
public interface I {}
public class Foo {
int bar(I i) {}
}
Now why does Java ... |
I am reading Thinking In Java at the moment and I encountered one small problem. I am doing exercise 12 from chapter 8.
Create an interface with at least one ... |
The following Java program just calculates the area of a circle. It uses the concept of inner classes available in Java. One of the inner classes (FirstInner) inherits it's enclosing class ... |
package com.foo; public class Super { protected void method() {} protected class Inner {} } ----------- package com.not.foo; import com.foo.Super; public class Sub extends Super { public static void main(String args[]) { Sub sub = new Sub(); sub.method(); //Of course this works! Super super = new Super(); //super.method(); Compiler complains- this is what I expect, but... //..why then can I directly ... |
What you have done is not multiple inheritance at all. Your outer class still extends only one superclass. Your inner class is a proper class all its own, just defined on the fly. So if we leave "multiple inheritance" out of the conversation ... Building an inner class like that to handle some task is common enough, especially with event handlers ... |
Hi, If I run this the output is My Frog speaking... class Frog { public static void main(String[] args) { Frog f = new Frog() { public void speak() { System.out.println("My Frog speaking..."); } }; f.speak(); } public void speak() { System.out.println("Frog speaking..."); } } If I run this the output is Frog speaking... class Frog { public static void main(String[] ... |
Hi! Got it worked, See below. Thanks -siva //: c08:IInheritInner.java // Inheriting an inner class. class WithInner { int x; String name; WithInner(int i, String str1 ){ System.out.println("WithInner"); x=i; name = str1; } class Inner { Inner(int y){ System.out.println("Inner"); System.out.println(y); } } } public class IInheritInner extends WithInner.Inner { //! InheritInner() {} // Won't compile IInheritInner(WithInner wi, int x) { wi.super(x); ... |
I'm wrestling with inner classes and so far inner classes are winning ... In Java in a Nutshell (5th ed, p147), Flanagan writes thus, discussing the difference between inheritance hierarchy and containment hierarchy: "There should not be a problem if you refrain from creating naming conflicts, where a field or method in a superclass has the same name as a field ... |
|
|
//:c07:BigEgg2.java //Properinheritanceofaninnerclass class Egg2{ protected class Yolk{ public Yolk(){ System.out.println("Egg2.Yolk()"); } public void f(){ System.out.println("Egg2.Yolk.f()"); } } private Yolky=new Yolk(); public Egg2(){ System.out.println("NewEgg2()"); } public void insertYolk(Yolkyy) {y=yy;} public void g() {y.f();} } public class BigEgg2 extends Egg2{ public class Yolk extends Egg2.Yolk{ public Yolk(){ System.out.println("BigEgg2.Yolk()"); } public void f(){ System.out.println("BigEgg2.Yolk.f()"); } } public BigEgg2() {insertYolk(newYolk());} public static void main(String[] args){ ... |
Hi everybody, I can't seem to find a clear answer on this, and it's probably a silly simple question, but here goes (it needs a little setup first)-- A base class X has two subclasses, Y and Z. Both Y and Z have static inner classes which contain a factory method that calls their constructors (that is, the methods call the ... |