Why this java program is not executing? code is below

0 votes
asked Feb 20, 2016 in JAVA by sudiptajava (520 points)
class Outclass {
    void newOutClass(ObjectAsParameter a) {
        a.sum(5, 5);
    }
}

public class ObjectAsParameter {

    void sum(int a, int b) {
        int z = (a + b);
        System.out.println("RESULT IS: " + z);
    }

    void alu(String[] args) {
        Outclass abir = new Outclass();
        abir.newOutClass(this);
        // Passing current object as a parameter to another method;
    }

}
commented Feb 20, 2016 by bari (2,940 points)

Where is the main method?

commented Feb 20, 2016 by sudiptajava (520 points)

Sir, please go for the link below:

https://www.youtube.com/watch?v=h7oY01ePtIA&index=14&list=PLayzfhgnsxfbxsr8GD_m3x2DOqlMyd1lf

There is no main method. But if i try to declare the " public static void main(String[] args) "
then it is a static method. In static method we can't use the " this " as a keyword to pass an object to another method.

I had watched this video. but may i haven't understand properly . if u help me then it will really helpful for me.

THANK YOU

commented Feb 21, 2016 by sudiptajava (520 points)

Sir i have posted my problem. Please help me out..

THANK YOU

1 Answer

+2 votes
answered Feb 22, 2016 by bari (2,940 points)

See the source code below

public class ThisRefEx {
    //instance variable
    int x;
    String y;

    public ThisRefEx(int x, String y) {
        // resolve ambiguity between insance variable and parameter
        this.x = x;
        this.y = y;
    }
    void sum(int x, int y){
        System.out.println(x+y);
    }

    void doYYY() {
        RecRef recref = new RecRef();
        // passing current object as a parameter to another method
        recref.doXX(this);
        recref.doMM(x);
    }
    public static void main(String[] args) {
        ThisRefEx trfex = new ThisRefEx(3, "H");
        trfex.doYYY();
    }
}

class RecRef {

    void doXX(ThisRefEx rr) {
       rr.sum(5, 6);         
    }

    void doMM(int s) {
    }
}
commented Feb 23, 2016 by sudiptajava (520 points)

THANK YOU SIR

Keep Going...

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
0 answers
asked Nov 18, 2015 in Java Swing by Kamrul (4,880 points)
0 votes
1 answer

722 questions

656 answers

179 comments

4,747 users

Welcome to IDB Scholars Forum, where you can ask questions and receive answers from other members of the community. It's 100% free.
আইডিবি স্কলারস ফোরামে আপনাকে স্বাগত - প্রোগ্রামিং, ডিজাইন, ডেভেলপমেন্ট, ব্লগিং, ইন্টারনেটসহ তথ্য প্রযুক্তির যাবতীয় বিষয় নিয়ে আলোচনার একটি মুক্ত মঞ্চ হলো এই ফোরাম । এখানে আইসিটি বিষয়ক আপনার প্রশ্ন, উত্তর এবং অভিজ্ঞতা শেয়ার করুন, আলোচনা করুন এবং সমাধান নিন। দেশের তরুণ প্রজন্মকে আইসিটিতে আগ্রহী করাই আমাদের মূল লক্ষ্য।
** ইংলিশ বা বাংলা যে কোনো ভাষায় আপনি এই ফোরামে আলোচনা করতে পারবেন। তবে বাংলাকে ইংরেজি অক্ষরে লিখবেন না।
  1. tulbadex

    110 points

    0 answers

  2. JettaQoa3381

    100 points

    0 answers

  3. clutch7conga

    100 points

    0 answers

  4. WhitneyMauer

    100 points

    0 answers

  5. pajamazipper55

    100 points

    0 answers

...