Skip to content

Instantly share code, notes, and snippets.

@caoakleyii
Last active June 6, 2016 00:02
Show Gist options
  • Save caoakleyii/e03ec9b9c13400fbfffde7a9d482cb48 to your computer and use it in GitHub Desktop.
Save caoakleyii/e03ec9b9c13400fbfffde7a9d482cb48 to your computer and use it in GitHub Desktop.
public class CloneMaker {
public void MakeClone() {
MyClone cloneA = new MyClone();
System.out.printLn(cloneA.fullName); // OUTPUT: "Daniel Waldron";
System.out.printLn(cloneA.firstName); // Won't compile, because of it's lack of access firstName is not defined.
System.out.printLn(cloneA.lastName); // Won't compile because of it's lack of access lastName is not defined.
cloneA.SayFirstName(); // OUTPUT: "Daniel";
cloneA.SayLastName(); // OUTPUT: "Waldron";
}
}
public class MyClone {
private string firstName = "Daniel";
private String lastName = "Waldron";
public String fullName;
public MyClone(){
fullName = firstName + lastName;
}
public static void main(String[] args) {
}
public void SayFirstName() {
System.out.printLn(firstName);
// this can read firstname
}
public void SayLastName() {
System.out.printLn(lastName);
// this can read lastname
}
}
@Dwaldron89
Copy link

run:
C:\Users\daniel.waldron\AppData\Local\NetBeans\Cache\8.0.2\executor-snippets\run.xml:48:
Cancelled by user.
BUILD FAILED (total time: 1 second)

@Dwaldron89
Copy link

/*

  • To change this license header, choose License Headers in Project Properties.
  • To change this template file, choose Tools | Templates
  • and open the template in the editor.
    */
    package myclone;

/**
*

  • @author daniel.waldron
    */
    public class MyClone {
    private String firstName = "Daniel";
    private String lastName = "Waldron";
    public String fullName;

    public MyClone(){
    fullName = firstName + lastName;
    }
    public static void main(String[] args) {

    }

    public void SayFirstName() {
    System.out.println(firstName);
    // this can read firstname
    }

    public void SayLastName() {
    System.out.println(lastName);
    // this can read lastname
    }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment