Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ OOP and JAVA OOP

  • 04-04-2005 10:52am
    #1
    Closed Accounts Posts: 7


    hello all... well this is my problem i have been doing c++ for 1.5 years and have started java about a month ago..now i have a good/strong understanding of oop a a concept but i have been having a problem joining the concept to the two languages for example in c++ i understand how a class is defined and initated but in java it seems a class can RETURN a value for example
    public string blah(){

    return stringans
    } is a class that returns a string..
    how is this possible where dose the class go and what data type is the returned value is it a string or a blah class...how is this Class that returns a value implemented in c++ and what is the benifit + dose this not make java a oop/procedureal language because in my mind a class that returns a value without calling 1 of its methods is more like a function..
    this to me seems to break the logic... i have a good feeling the returned value is a String but again this makes the class blah more like a function....i would love to see a bit of code with a class in c++ that returns a value and some sort of example as to why this is a good oop idea..thanks in advance


Comments

  • Registered Users, Registered Users 2 Posts: 2,013 ✭✭✭lynchie


    public String blah(){..} is a method (function in c talk). It is not a class but a method within a class. A class in Java is defined as public class Blah{...}


  • Closed Accounts Posts: 7 MDMA


    so ur saying that oop in java still uses functions ah ...that dose make sense...i do intend on reading a good mamoth of a book on all this java oop but as for now i want to see how far i go without forking out for a book...+ i can t read online so thinking in java is no good b4 u reply suggesting it ..sorry just cant read off the comp screen...anyway yes that dose help a little but just to clarify

    public class blah(){
    } is a class which must have 1 main "method"

    public void static main(String[] args){
    }//ah so this is a method not a class ah is see.good stuff

    thanks


  • Registered Users, Registered Users 2 Posts: 4,003 ✭✭✭rsynnott


    No need for a book, Java OO is easy if you already know C++ OO.

    Classes should be defined in .java files of the same name, case sensitive. You'll get away with case-insensitivity on Windows, but you'd be in trouble if you ever wanted to compile on a UNIX.

    All methods are defined WITHIN classes, eg:
    public class Thing{
    Thing(){
    /* Do Stuff */
    }
    }

    Only classes which are actually executable need a main function.

    The main function is static; it's often useful to create an instance of the main class within the main function, and transfer control to that.

    There's no operator overloading or multiple inheritance. An effect similar to multiple inheritance can be achieved by using interfaces:
    Interface ThingInterface{
    public String Something();
    }
    Interfaces just contain prototypes, and a class can implement unlimited interfaces:
    public class AThing extends Thing implements ThingInterface, ThingInterface2{....

    Everything is pass-by-reference except basic data types (boolean,int,float,double, etc.)

    Those are the big differences I can think of offhand.


  • Closed Accounts Posts: 7 MDMA


    Ah good stuff that clears up a few things..I know the java oop is easy enough but then im a newbie ha ha.. well onward's it is so got to learn lots of java....


    thanks again
    Scott McNealy
    CEO, HOT_Sun Microsystem, Inc ha ha


Advertisement