Java Packaging Exercises 2

Source: Internet
Author: User

 PackageA;//write a Class father in package A with attributes: Age (private), name (public);//Features: Work (public), drive (public). //write a subclass in package a son, with attributes: Age (protected), name;//Features: Play (private), learn (public). //Finally, write the main class test in package B, and test the class father and class son in the main method of the Master class.  Public classFather {Private intnianling;  Public intgetnianling () {returnnianling; }     Public voidSetnianling (intnianling) {         This. nianling =nianling; }     PublicString xingming;  Public voidgz () {System.out.println (Work); }     Public voidKC () {System.out.println (Drive); }

 Package A;  Public class Son {    protectedint  nianling;     protected String xingming;     Private void Wan () {                System.out.println ("Play");    }              Public void Xuexi () {        System.out.println ("learning");    }        
 Packageb;ImportA.father;ImportA.son; Public classTest { Public Static voidMain (string[] args) {//TODO Auto-generated method stubsFather F=NewFather ();        F.gz ();        F.KC (); Son s=NewSon (); //S.wan (); There are error methods not visibleS.xuexi (); }

Java Packaging Exercises 2

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.