Java Classes vs. C Structs


Java is an object-oriented programming language. C is not. The C language does not support objects. The closest C comes to defining an object is the struct or union programming constructs. As you probably know, a struct is a collection of named data members. The data members can be of different types. You can declare a struct variable that is a reference to a struct . The values of the struct data members can be accessed by typing the struct variable name, a period, and the data member name .

If you are familiar with using structs , it shouldn't be too great a leap to become familiar with the concept of a class. A Java class is basically just a named block of code that defines a collection of both fields and methods . A class is more self-contained than a struct in that a class can (and should) define all the methods required to manipulate its data members. Java classes can make use of the powerful object-oriented concepts of inheritance, polymorphism, and encapsulation. There are many different types of classes according to whether one or more modifying keywords are applied to them. You can have public and private classes, abstract and final classes. You can nest a class definition inside another class definition

You can create instances of a class. A class instance is also known as an object. You can declare variables that are references to class instances. A class can define a class instance as one of its fields.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net