"Good programmer training Camp" Java classes and objects

Source: Internet
Author: User

Java supports the concepts of the following classes and objects:

Polymorphism, inheritance, encapsulation, abstraction, class, object, instance, method.

Like books, can also be divided into Chinese books, math books, history books and so on, each book has a different content.

An example of a simple employee:

The employee class has four member variables: name, age, designation, and salary. The class explicitly declares a constructor method that has only one parameter.

public class Test {public static class employee{string Name;int age; String design;double salary;public Employee (string name) {This.name=name;} public void Setage (int.) {this.age=age;} public void Setdsign (String des) {this.design=des;} public void Setsalary (double salary) {this.salary=salary;} public void Printemployee () {System.out.println ("Name" +name); System.out.println ("Age" +age); System.out.println ("Designtion" +design); System.out.println ("Salary" +salary);} public static void Main (String args[]) {Employee Emp1=new employee ("Zhang San"); Employee Emp2=new Employee ("John Doe"), Emp1.setage, Emp1.setdsign ("Program Ape"), Emp1.setsalary (10000); Emp1.printemployee () ; emp2.setage; emp2.setdsign ("Small program Ape"); Emp2.setsalary (8000); Emp2.printemployee ();}}
Operation Result:



"Good programmer training Camp" Java classes and objects

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.