Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 26-07-2008, 10:04 PM   #1 (permalink)
Indidiot
 
Plasma_Snake's Avatar
 
Join Date: Dec 2007
Location: Rock Island
Posts: 1,416
Default JAVA Query


Consider a scenario;
class2 extends class1
{
--some code--
}

class3 extends class2
{
--some code--
}
Now since its a text book example of Hierarchical Inheritance, is it possible:
  1. for class3 to access a method of class1?
  2. If Super is used whose Constructor is called, class1's or class2's ?
  3. Is there a provision of "Friend" type access specifier that can enable the usage of Private members of Super class in a sub class?
Plasma_Snake is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 26-07-2008, 10:30 PM   #2 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: JAVA Query

1. Yes it can access it as normally as class 2 would access it.

2. super() would call the class2's constructor, but it'd also trigger the constructor-chain which will call class 1 and so on. You need to be careful with that.

3. Not exactly, but you can use something called as a "Package" to work around this issue.

Here's an example regarding the first two questions:

Code:
class Foo
{
    Foo()
    {
        System.out.println("Foo-Constructor Called.");
    }
    
    // Below one won't show up cause its not explicitly called.
    // But the Foo() is called nevertheless, after Bar(someInt)
    
    Foo(int someInt)
    {
        System.out.println("Foo-Constructor Called with " + someInt);
    }
    
    void doFoo()
    {
        System.out.println("Foo did something.");
    }
}

class Bar extends Foo
{
    Bar()
    {
        System.out.println("Bar-Constructor Called.");
    }
    
    Bar(int someInt)
    {
        /* super(someInt); */
        System.out.println("Bar-Constructor Called with " + someInt);
    }
    
    void doBar()
    {
        System.out.println("Bar did something.");
    }
}

class Spam extends Bar
{
    Spam()
    {
        super(16);
        System.out.println("Spam-Constructor Called.");
    }
    
    void doSpam()
    {
        System.out.println("Spam did something.");
    }
}

class Eggs
{
    public static void main(String args[])
    {
        Spam objSpam = new Spam();
        objSpam.doFoo();
        objSpam.doBar();
        objSpam.doSpam();
    }
}

// Eggs.java
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 27-07-2008, 03:28 AM   #3 (permalink)
Indidiot
 
Plasma_Snake's Avatar
 
Join Date: Dec 2007
Location: Rock Island
Posts: 1,416
Default Re: JAVA Query

Besides Netbeans, can we use Visual Studio to Create,Compile and Run simple JAVA programs?
Plasma_Snake is offline  
Old 27-07-2008, 06:59 AM   #4 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: JAVA Query

I'm afraid not, but there's Microsoft's J# that comes close enough to Java and is available in the full-fledged versions of Visual Studio.

You can try Eclipse / JCreator / JBuilder instead as alternatives?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 27-07-2008, 07:08 AM   #5 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: JAVA Query

Quote:
Originally Posted by QwertyManiac View Post
I'm afraid not, but there's Microsoft's J# that comes close enough to Java and is available in the full-fledged versions of Visual Studio.

You can try Eclipse / JCreator / JBuilder instead as alternatives?
Or u can use Notepad++ / Vim / Kete if u love to type n then manually compile programs...
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 27-07-2008, 08:32 AM   #6 (permalink)
OSS Enthusiast!
 
nitish_mythology's Avatar
 
Join Date: Sep 2005
Location: Hills of Kumaoun
Posts: 664
Default Re: JAVA Query

Another leight weight IDE -- Geany . Found it quite impressive.
__________________
Do you know, Shinigamis only eat apples???
nitish_mythology is offline  
Old 01-08-2008, 03:28 PM   #7 (permalink)
Indidiot
 
Plasma_Snake's Avatar
 
Join Date: Dec 2007
Location: Rock Island
Posts: 1,416
Default Re: JAVA Query

This is a simple program of implementing "Super" and "Inheritance". I made it using Netbeans 5.5.1 and when compiled it, gave some errors. I, then copied the code in Notepad and when Compiled and executed the program in Command prompt, it worked fine and produced the output as expected. What went wrong in case of Netbeans? I used the same JDK for compiling and executing the program, one used by Netbeans(present in Netbeans folder). below are both, the Netbeans project file and the Notepad one. Please check them and tell me what was wrong?
Attached Files
File Type: zip JavaFiles.zip (14.9 KB, 2 views)
Plasma_Snake is offline  
Closed Thread

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
Java programming..how can I distribute java program....? Manojap Programming 5 16-05-2009 02:46 PM
What is more powerfule Core Java or Java ? avadhesh QnA (read only) 4 06-05-2008 04:55 PM
Java programming query navjotjsingh Programming 7 27-10-2007 01:18 AM
c++, java and more mak1012 Open Source 11 10-08-2006 03:47 PM
Microtek Monitor Query and PHPBB Attachment Mod Query vwad Software Q&A 1 20-03-2005 09:32 AM

 
Latest Threads
- by Sujeet
- by clmlbx
- by Sujeet
- by icebags

Advertisement




All times are GMT +5.5. The time now is 11:07 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2