Difference between Object and Class in Java

Difference between Object and Class in Java

Understanding Object and classes in java are very important.This article will explain into details the difference between Object and a Class.

The object has both logical and physical entity whereas Class contains only logical entity.

Object


Generally, a Object has 3 xstics.

  • State-This is object data.
  • Behaviour-This is object functionality e.g delete, deposit etc.
  • Identity -each object has a unique identity which is not visible to the user.
Object is normally an instance of a class.Class is a template from which we are able to create new objects.

Class

Class is a group of objects with similar xstics.A class can contain-:
  • Fields
  • Methods
  • Constructors
  • blocks
  • nested class and interface.
New keyword is used to create a new Object.

Syntax for creating a class


class {  
    field;  
    method;  
}  

Example code showing class and object


public class Account {
    public String name;
    public int id;
    public double balance;
    
    public void setName(String n)
    {
        name=n;
   }
  
    public String getName()
        {
        name=this.name;
        return name;
        }
    public void setID(int idnumber)
    {
    id=idnumber;
    }
    public int getID()
    {
    id=this.id;
    return id;
    }
    public void setBalance(double bal)
    {
    balance=bal;
    }
    public double getBalance()
    {
    balance=this.balance;
    return balance;
    }
    Account()
    {
        setName("Eric Mutua");
        setID(27958503);
        setBalance(1234.50);
          System.out.println("Account Details");
        System.out.println("=====================================");
        System.out.println("Account Name "+getName() );
         System.out.println("ID Number "+getID() );
          System.out.println("Balance "+getBalance() );
        
          System.out.println("=====================================");
    
    }
    public static void main(String args[])
    {
    new Account();
    }
    
}

Output


Related Articles:


COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: Difference between Object and Class in Java
Difference between Object and Class in Java
Difference between Object and Class in Java
https://1.bp.blogspot.com/-0mXCDNymXrA/WQCvzOrlnPI/AAAAAAAAHvo/tD4lhNU60q8LqxNDrctUfRxBe1nbnRIQwCLcB/s320/object-and-class-in-java.PNG
https://1.bp.blogspot.com/-0mXCDNymXrA/WQCvzOrlnPI/AAAAAAAAHvo/tD4lhNU60q8LqxNDrctUfRxBe1nbnRIQwCLcB/s72-c/object-and-class-in-java.PNG
Java Codes
http://www.download-all.net/2017/04/difference-between-object-and-class-in.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/04/difference-between-object-and-class-in.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy