the above explanation is very nice.
However, I am slightly confused by the implementation of Decorator Pattern (DeP) as given in
http://www.netobjectives.com/resources/books/design-patterns-explained/java-code-examples/chapter17/#17-1
The design for above linked code is given ... |
What is the difference between this keyword and super keyword? Both are used to access constructors of class right? Can any of you explain?
|
When, in a constructor, we use the super keyword, do we have to import the class the super refers to (when super doesn't refer to Object)?
class A extends ... {
...
|
I've noticed that:
class A {
ClassB b = new ClassB() { // anonymous class
/* some expression using this */
...
|
Check my coolMethod, babes:
package zoo;
public class Zoo {
public String coolMethod() {
return "Wow baby!";
}
}
My Moo Class, ... |
In the book "Java in a Nutshell", chapter 3, section 3.5 Subclasses and Inheritance, there is such as paragraph about the usage of super to access overriden method:
Note that ... |
I am still trying to learn java, so correct me if I'm wrong.
As I understand it, the super keyword calls the constructor of a class. So I do not ... |
|
Hi, I wonder, in the example below, where does the method from a superclass returns its output (a collection): public Collection getChildrenFeatures(Object object) { if (childrenFeatures == null) { super.getChildrenFeatures(object); //here* childrenFeatures.add(LibraryPackage.eINSTANCE.getLibrary_Writers()); childrenFeatures.add(LibraryPackage.eINSTANCE.getLibrary_Books()); } return childrenFeatures; } protected Collection getChildrenFeatures(Object object) { if (childrenFeatures == null) { childrenFeatures = new ArrayList(); } return childrenFeatures; } * why is it not necessary ... |
public class SubClass extends SuperClass { public int value = 10; public void SayHello() { System.out.println("Hello World, from SubClass"); super.SayHello(); } public void ShowValue() { System.out.println("Value in SubClass: " + value); System.out.println("Value in SuperClass: " + super.value); } public static void main (String args[]) { SubClass app = new SubClass(); app.SayHello(); app.ShowValue(); } } |
sorry abt the incomplete posts..here is the proper one.. super refers to the object's immediate parent. U can use the super keyword to explicitly call a base class method. Calling super in the constrcutor calls the base class constructor. Here is a small sample to clarify things: class Base { private String name; Base(String name) { this.name = name; } } ... |
The correct answer is, yes and no. The compiler will happily let you call the static method from the superclass with the super keyword, but it is not necessary.public class Foo { public static int add(int i, int j) { return i + j; } } public class Bar extends Foo { private int i; . . . public int increment(int ... |
i read the following in the sun java tutorials: source: http://java.sun.com/docs/books/tutorial/java/IandI/subclasses.html You can write a subclass constructor that invokes the constructor of the superclass, either implicitly or by using the keyword super. source: http://java.sun.com/docs/books/tutorial/java/IandI/super.html Using the Keyword super Accessing Superclass Members If your method overrides one of its superclass's methods, you can invoke the overridden method through the use of the ... |
it's budsy again and i hope that by now administrators recognize me. I was studying cloning and it lead me to understand protected access better:- here is the code which i don't understand package one; public class Obj { protected void method() { } } Second class that will be importing package one import one.*; public class ObjImplement extends Obj { ... |
Ok guys, I'm really hoping you can help me out with this one because I'm at the end of my rope in trying to understand the following: class Animal { Animal() {System.out.print("animal"); } } class Horse extends Animal { Horse (String type) {System.out.print(type);} } public class Pony extends Horse { Pony(){ super("black"); new Horse("black"); } public static void main (String[] a) ... |
hello, I've developed these two classes, they are related by inheritance when the last line executed in main , i want the "toString()" in the subclass call the "toString()" in the super class I've tried to put this line "super.toString()" inside the the method in the subclass but it give me syntax error I'd be grateful if you help me thanks ... |
class A { int i=3; void hello(); { System.out.println("I am inside A"); } } class B extends A { int i=5; void hello(); { System.out.println("I am inside B"); } } class C extends B { int i=7; void hello(); { System.out.println("I am inside C"); } System.out.printlin("Value of i in C is:" + i); System.out.printlin("Value of i in B i:" + super.i); ... |
class A class B extends A class C extends B class main extends C { // in this class I want to call the constuctor of class A , without invoking the constructor of class B & C } is it possible ? IF possible , post the couple of lines of code , that can simply exibits the solution. |
hi , i just have a question , which is with this line ConsDemo c = new ConsDemo(10); my constructor of consdemo class is getting envoked and the value ie. 10 is assigned to size variable . with this line Cons c1 = new Cons(20); my constructor of cons class is getting envoked and the value ie. 20 is assigned to ... |
|
Java Code: class Parent { private String name; public int nr; public Parent(String n) { this.name = n; nr = 10; } } public class Child extends Parent { // since the Parent has no default constructor // the first statement in the constructor of the Child class must // be a call to the non default constructor // otherwise you ... |
First of what are bound to be pretty stupid questions. Any help is greately appreciated. I'm a bit confused by the use of the super keyword in the code below I understand that the super keyword forces invocation of the superclass method onCreate and the reason I have to do this is because I've extended the Activity class. If I remove ... |
|
|
|
|
|
package pack; import java.io.*; import java.util.*; class Samp1 { public Samp1()//default constructor {} String name; int empid; float sal; public Samp1(String name,int empid,float sal) { this.name=name; this.empid=empid; this.sal=sal; } public void disp(String name,int empid,float sal) { System.out.println("Name of the Employee:"+name); System.out.println("Employee ID of the Employee:"+empid); System.out.println("Salary of the Employee:"+sal); } } class SubSamp1 extends Samp1 { public static void main(String[] args) ... |
JLS uses this statement:the keyword super.But what does it mean? Is it a reference or something else?Books only tell guys how and where use "super", without explaining clearly. Why we cannot just print it just as other variables in this way: System.out.println(super). This has confused me for a pretty long time. Everyone try your best to help me.Thx~Aha |
Above code says that every class has a this & a super reference which holds the current object of that class type. But how can we refer this & super by using class name ???.....this & super are not static as if we try to use this & super from static block/function then compiler gives error saying this/super cann't be referenced ... |