Is it possible to override constructor and instance initializer?

In the source below, I found that all 4 System.out.println() messages are printed.
Is it possible to have the constructor and instance intializer in ClassC overrides that of ClassB?
import java.util.*;
class ClassB {
          System.out.println("Hello");     
     ClassB() {
          System.out.println("HaHa");     
class ClassC extends ClassB {
          System.out.println("Hello1");     
     ClassC() {
          System.out.println("HaHa1");     
public class Test1 {
     public static void main(String[] args) {
          ClassC c = new ClassC();
}

You can't override an instance initializer, no. And when you create an object, some constructor of each of its superclasses must be called to do the creating. In your example, it's the default constructor of ClassB that's called. ClassC's constructor must call some constructor of ClassB.

Similar Messages

  • Classes, and constructors and instance variables . . . oh my!

    wow, I am really struggling with the stuff we are doing in class for the last few days. I am going to post our assignment and point out specific things I don't understand. I don't understand some of the syntax and the overall logical flow of how parameters get passed back and forth, etc. I have been over our book and class examples and I am still confused.
    Here is one part of the assignment:
    "Create two instances of the MyDate class named begDate and endDate, by using the MyDate constructor after having prompted the user
    3 times for each date for values of a valid month, day, and year."
    Q: how do I create two instances using the constructor?
    (from our assignment) "Within the MyDate class:
         Include three private int variables, named month, day, and year.
         Include a constructor that sets (sets them to what?!) the values of month, day, and year."
    here is what I have:
    public class MyDate {
         private int month, day, year;
         public MyDate (int month, int day, int year){
              month = 0;
              day = 0;
              year = 0;
         }//MyDate Constructor(from our assignment) "Create two instances of the MyDate class named begDate and endDate, by using the MyDate constructor after having prompted the user 3 times for each date for values of a valid month, day, and year."
    and here is what I have in the executable class (it isn't much because I already have an error; it says I can't convert String to MyDate):
    public static void main(String[] args) {
              MyDate begDate = JOptionPane.showInputDialog("beg. month?");
         }I guess I don't know how to use the constructor correctly. Sorry, but I have tried to make this as clear as possible.

    I will give you a start:
    public static void main(String[] args) {
              MyDate begDate new MyDate(JOptionPane.showInputDialog("beg. month?"), JOptionPane.showInputDialog("beg. day?"), JOptionPane.showInputDialog("beg. year?"));
    public class MyDate {
         private int month, day, year;
         public MyDate (int month, int day, int year){
              this.month = month;
              this.day = day;
              this.year = year;
         }//MyDate Constructor
    /code]
    Haven't tested it, maybe made some type mismatches, but at leasy try this one                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Is it possible to override super class constructor?

    Is it possible to override super class constructor form subclass?

    However, you can achieve do something that looks similar to overriding.
    class Parent {
      Parent(int i, String s) {
        // do stuff
    class Child extends Parent {
      Child(int i, String s) {
        super(i, s);
        // do Child stuff here
    new Parent(1, "abc");
    new Child(2, "xyz");Although that's not overriding, it sort of looks similar. Is this what you were talking about?

  • Is it possible to have source and target schema in the same DB instance ?

    Hi All,
    I'm using Oracle 11gR1.
    I have switched source locations from other server to the one with OWB.
    During deploy I get VLD-3064 and I can't deploy mapping because of many 'table or view does not exist' warnings.
    Is it possible to have source and target schemas in the same instance ??
    How to do it ?
    Regards,
    Martin

    Hi Jörg,
    Thanks for your help and quick answer.
    I'd like to clarify a little your answer :
    1. Are the any special privilages I need to set ? Currently I have only 'RESOURCE' and 'CONNECT' (I think I didn't have to add any other privs when that schema was located on other instance...)
    2. Also VLD-3064 states that : 'Owning and referenced location of this connector are on the same database instance. Unless explicitly referenced in configuration settings no generated code will use the dataabase link resulting from deployment of this connector'. Does it mean I have to put something in configuration ?
    Thanks,
    Martin

  • Question about abstract classes and instances

    I have just read about abstract classes and have learned that they cannot be instantiated.
    I am doing some exercises and have done a class named "Person" and an abstract class named "Animal".
    I want to create a method in "Person" that makes it possible to set more animals to Person objects.
    So I wrote this method in class Person and compiled it and did not get any errors, but will this work later when I run the main-method?
    public void addAnimal(Animal newAnimal)
         animal.add(newAnimal);
    }Is newAnimal not an instance?

    Roxxor wrote:
    Ok, but why is it necessary with constructors in abstract classes if we don�t use them (because what I have understand, constructors are used to create objects)?Constructors don't create objects. The new operator creates objects. An object's c'tor is invoked after the object has already been created. The c'tors job is to initialize the newly-created object to a valid state. Whenever a child object is created, the parent's c'tor is run before the child's c'tor, so that by the time we're inside the child's c'tor, setting up the child's state, we know that the parent (or rather the "parent part" of the object we're initializing) is in a valid state.
    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Is it possible to override the built-in PDF format handler with a custom IFilter for PDF?

    Hi,
    SharePoint 2013 comes with a built-in "format handler" for PDF now, so it can index PDF files out of the box. This is great for most users, as it now no longer is necessary to install a third-party IFilter for crawling PDF documents.
    My question is, is it possible to override the built-in format handler for PDF with a custom IFilter for PDF? I played with the Set-SPEnterpriseSearchFileFormatState and Remove-SPEnterpriseSearchFileFormat cmdlets. While it is possible to deactivate
    the built-in format handler, I was not able to remove it and to create a new one that activates a custom IFilter for PDF files.
    Background of the question: While the new built-in format handler for PDF will probably be sufficient for many SharePoint users, some need additional capabilities regarding indexing if PDF documents, e.g. extraction of custom metadata from PDF's document
    information dictionary and embedded XMP metadata. PDFlib GmbH, the company I work form, sells an IFilter for PDF, and of course we would like to continue to offer this for SharePoint 2013.
    Thanks
    Stephan

    You should be able to replace it with any ifilter you want, this is the procedure for installing it:
    Install PDF iFilter 9.0 (64 bit) from
    http://www.adobe.com/support/downloads/detail.jsp?ftpID=4025 (http://www.adobe.com/support/downloads/detail.jsp?ftpID=4025)
    Download PDF icon picture from Adobe web site
    http://www.adobe.com/misc/linking.html (http://www.adobe.com/misc/linking.html)  and copy to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\IMAGES\
    Add the following entry in docIcon.xml file, which can be found at: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\XML
    <Mapping Key="pdf" Value="pdficon_small.png" />
    Add pdf file type on the File Type page under Search Service Application
    Open regedit
    Navigate to the following location:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\15.0\Search\Setup\ContentIndexCommon\Filters\Extension
    Right-click > Click New > Key to create a new key for .pdf
    Add the following GUID in the default value
    {E8978DA6-047F-4E3D-9C78-CDBE46041603}
    •Restart the SharePoint Server Search 15
    •Reboot the SharePoint servers in Farm
    •Create a Test site (with any out-of-box site template) and create a document library upload any sample PDF document(s).
    •Perform FULL Crawl to get search result.
    Once the crawl is completed we will get search results.
    Kind regards,
    Margriet Bruggeman
    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • Is it possible to override built-in forms procedures like call_form?

    hi, is it possible to override built-in forms procedures like call_form? i want to override an existing built-in procedure so i don't need to change all my .fmbs. thanks in advice

    Hi,
    You cannot override them. However, you can create a procedure within the package with the name call_form and use it as package_name.call_form instead of call_form (use the search and replace functionality to replace the call_form with package_name.call_form).
    -Arun

  • ECP CI Start and Instance Profile not showing in RZ10

    Hi,
    I am not able to access or view our ECP Central Instance Start and
    Instnace profile for ECP CI Instance in RZ10 , I do not see the start
    and instance profile for ECP CI Instance. However, I do see start and
    instance profiles for APP1 and APP2 instance, but just not CI instance.
    So, when I try to re-import the profiles I get the below error message.
    I wanted to check if it is access related, so, I logged on the the ECP
    CI Server physicall and had tried to accessed the ECP
    CI Server and try to access the below path from start --> run -->
    SAPGRPPRD\sapmnt\ECP\SYS\profile\ECP_DVEBMGS02_ECC-Prod-CIS and
    SAPGRPPRD\sapmnt\ECP\SYS\profile\START_DVEBMGS02_ECC-Prod-CIS and it
    works. But the profiles are not being read
    From ECP CI RZ10. Can you please advise why this is not showing.
    Error Message when i try to import the profiles:
    Log for the import of profiles
    Instance profile
    SAPGRPPRD\sapmnt\ECP\SYS\profile\ECP_DVEBMGS02_ECC-
    Prod-CI Could not be read. The import is therefore not possible.
    Start profile
    SAPGRPPRD\sapmnt\ECP\SYS\profile\START_DVEBMGS02_ECC-
    Prod- Could not be read. The import is therefore not possible.
    Instance profile
    SAPGRPPRD\sapmnt\ECP\SYS\profile\ECP_DVEBMGS02_ECC-
    Prod-CI Could not be read by file; Therefore could not be checked.
    (Server = ECC-Prod-CIS_ECP_02 )
    Please advise?

    Hi,
    I logged on the the ECP
    CI Server physicall and had tried to accessed the ECP
    CI Server
    as per above statment you have login to CI and try to call CI proifle file manually. then can you tell us why this both the host name are different.
    SAPGRPPRD
    ECC-Prod-CIS
    Thanks
    Anil

  • Is it recommended to support multiple DBs and Instances on same RAC nodes

    Customer wants to install multiple databases on the same set of 3-nodes essentially making all these database 3-node rac databases on Sun fire servers.
    Is this a recommended approach? What are the pitfalls?
    Can this be done effectively without using local containers (which are not supported for RAC)?

    The Customer would save significantly on Licencing if he does not have to add Processors into the three nodes.
    Processor Based Licences don't count the number of databases and instances, only the number of CPUs (Processors).
    Setting up seperate Clusters requires that many Processor Licences.
    However, using multiple Standard Edition RAC installations (Linux and ASM) would have been another option.
    I have run multiple databases on a single Cluster in 9iRAC. I am sure that there are customers running multiple databases in a single Cluster in 10gRAC. You'd have only one CRS and one ASM Home in each node but it may be possible to have separate Database ORACLE_HOMEs in each node as well.

  • Message Server Port and Instance Number

    Hi All,
    I need to create Technical System and Business System in SLD for my IDOC-XI-FILE Scenario. There i need to specify the Message Server port under Message Server and Instance Number in Central Application Server. Please let me know where i have to found these. Please help as soon as possible.
    Thanks & Regards,
    Nagarjuna.

    Hi Nagarujna,
    Instance Number : - just check the logon pad.. select your Ecc or R/3 system and click on chane item....  Usally it is 00.
    Message server port : it is 3600 + instance no.
    3600 + 00 = 3600
    Sachin

  • Constructor and Class constructor

    Hi all
    Can any one explain me the functionality about Constructor and class constructor??
    As well as normal methods, which you call using CALL METHOD, there are two special methods
    called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are automatically called when you
    create an object (CONSTRUCTOR) or when you first access the components of a class
    (CLASS_CONSTRUCTOR)
    I have read the above mentioned document from SAP Documents but i found it bit difficult to understand can any one please help me on this??
    Thanks and Regards,
    Arun Joseph

    Hi,
    Constructor
    Implicitly, each class has an instance constructor method with the reserved name constructor and a static constructor method with the reserved name class_constructor.
    The instance constructor is executed each time you create an object (instance) with the CREATE OBJECT statement, while the class constructor is executed exactly once before you first access a class.
    The constructors are always present. However, to implement a constructor you must declare it explicitly with the METHODS or CLASS-METHODS statements. An instance constructor can have IMPORTING parameters and exceptions. You must pass all non-optional parameters when creating an object. Static constructors have no parameters.
    Class Constructor
    The static constructor is always called CLASS_CONSTRUCTER, and is called autmatically before the clas is first accessed, that is before any of the following actions are executed:
    Creating an instance using CREATE_OBJECT
    Adressing a static attribute using ->
    Calling a ststic attribute using CALL METHOD
    Registering a static event handler
    Registering an evetm handler method for a static event
    The static constructor cannot be called explicitly.
    For better understanding check the following code:
    REPORT  z_constructor.
          CLASS cl1 DEFINITION
    CLASS cl1 DEFINITION.
      PUBLIC SECTION.
        METHODS:
          add,
          constructor IMPORTING v1 TYPE i
                                v2 TYPE i,
          display.
        CLASS-METHODS:
         class_constructor.
      PRIVATE SECTION.
        DATA:
        w_var1   TYPE i,
        w_var2   TYPE i,
        w_var3   TYPE i,
        w_result TYPE i.
    ENDCLASS.                    "cl1 DEFINITION
          CLASS cl1 IMPLEMENTATION
    CLASS cl1 IMPLEMENTATION.
      METHOD constructor.
        w_var1 = v1.
        w_var2 = v2.
      ENDMETHOD.                    "constructor
      METHOD class_constructor.
        WRITE:
        / 'Tihs is a class or static constructor.'.
      ENDMETHOD.                    "class_constructor
      METHOD add.
        w_result = w_var1 + w_var2.
      ENDMETHOD.                    "add
      METHOD display.
        WRITE:
        /'The result is =  ',w_result.
      ENDMETHOD.                    "display
    endclass.
    " Main program----
    data:
      ref1 type ref to cl1.
    parameters:
      w_var1 type i,
      w_var2 type i.
      start-of-selection.
      create object ref1 exporting v1 = w_var1
                                  v2 = w_var2.
       ref1->add( ).
       ref1->d isplay( ).
    Regards,
    Anirban Bhattacharjee

  • Instance initializer and static initializer blocks

    Hi guys,
    I read about the above mentioned in the JLS and also in a book before, but I still don't quite understand, what is the use of these. I sort of have a rough idea, but not exactly. I mean, what is the purpose of the instance initializer and static initializer blocks, how can it be useful? I understand I can execute pieces of code that will initialize instance and static variables accordingly, but how is it different then to using a constructor to initialize these fields? Are these pieces of code executed before any constructor is executed, or when otherwise?
    Sorry for my noob, I'm learning.
    PR.

    Static initializers are useful for initializing a class when the initialization is more complex than simply setting a single variable, or when that initialization can throw a checked exception.
    public class Foo {
      private static final Bar bar;
      static {
        try {
          bar = new Bar();
          bar.doSomeInitializationStuff();
        catch (SomeCheckedExceptionThatBarThrows e) {
          throw new ExceptionInInitializerError(e);
    }Here we could not do the two-step new Bar() + doSomeInit() stuff in the line where we declare the bar variable. Additionally, assuming that one or both of those can throw a checked exception, we could not do that on the declaration line; we need the static initializer to wrap that in the appropriate unchecked exception.
    This allows us to do more complex class initialization when the class is loaded than we could do with a simple variable initialization.
    Instance initializers are useful if you want to perform the same steps in every constructor and don't want to have to repeat the code in each constructor. Instance initializers are executed as the first step of each constructor (or maybe it's after any super() calls, I forget).

  • Is it possible to automatically unwrap all instancies of a element in Frame 7.2 ?

    Hi all, Is it possible to automatically unwrap all instancies of a element called "Table Cell" in Frame 7.2 ? I can unwrap manually but there are over 400 instanticies!! No longer needed due to a template update. Thanks in advancce

    If you have an XML application set up that supports both import and export, you could
    include a very simple XSLT transform in one direction that does the unwrapping.
        --Lynne

  • Is it possible to Override Flex Default behaviour of loading Images on mouse scroll over ??

    Hi ,
    I am displaying Images on to a DataGrid .
    This works fine .
    My question is that  ,  Flex 3 is not loading all the Images at once , its loading Sometimes on mouse scroll down on a
    browser and sometimes on Mouse down .
    I dont want to have this behaviour , is it possible to override such behaviour and load all the Images at once ??

    Hi,
    What has been going wrong with your post ? You can use external USB sound card for your laptop. Here are few of them:
      http://www.shopbot.com.au/external-sound-card-usb/​price/australia/582295
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • Is it possible to override authorative reverse DNS lookups?

    Hello,
    I am part of collaborative workgroup which has a group of networked computers that are installed at each others sites. This means that often a server has two names - a "site name", which is the name in DNS, such as BigFoot.yale.edu at X.X.X.5 and a "workgroup name", the name used by the group for distributed processes, such as YaleBigFoot.workgroup.net also at X.X.X.5 in our /etc/hosts file.
    We are trying to use globus and GSI authentication in between the servers which requires valid reverse dns lookups, such that a CN=host/ .
    On unix'y servers, this requires setting up a rather comples /etc/hosts and editing /etc/nsswitch so that /etc/hosts is used authoritively for all lookups.
    I have been trying to replicate this behavior for our Mac users, and I'm running into problems. I have read all the "reverse dns" documentation I can - and it appears that my problem is different.
    I have setup a /etc/hosts file and a /etc/lookupd/hosts configuration file and a /etc/named.conf section for workgroup.net and a /var/named/workgroup.net.zone file.
    However I still get the following output:
    $ host yale-bigfoot.workgroup.net
    yale-bigfoot.workgroup.net has address X.X.X.5
    $ host X.X.X.5
    X.X.X.5.in-addr.arpa domain name pointer workgroup-router-node.net.yale.edu.
    Is it possible to override the authorative reverse lookups?
    Thank you in advance,
    Brendan
    PS: names and address are not actual
    17' SuperDrive Powerbook G4   Mac OS X (10.4.6)  

    However, you can achieve do something that looks similar to overriding.
    class Parent {
      Parent(int i, String s) {
        // do stuff
    class Child extends Parent {
      Child(int i, String s) {
        super(i, s);
        // do Child stuff here
    new Parent(1, "abc");
    new Child(2, "xyz");Although that's not overriding, it sort of looks similar. Is this what you were talking about?

Maybe you are looking for