Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
39 changes: 39 additions & 0 deletions 39 Chapter11/Creating_a_Thread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Create a thread by implementing Runnable.
class MyThread2023 implements Runnable{
// Objects of MyThread can be run in their own threads because MyThread implements Runnable.

String thrdName;

public MyThread2023(String name) {
thrdName = name;
}

// Entry point of thread.
public void run() { // Threads start executing here.

System.out.println(thrdName + " starting.");

try {
for (int count = 0; count < 10; count++) {

Thread.sleep(400);

System.out.println("In " + thrdName + ", count is " + count);
}
} catch (InterruptedException exc) {
System.out.println(thrdName + " interrupted.");
}

}

}


public class Creating_a_Thread {

public static void main(String[] args) {
// TODO Auto-generated method stub

}

}
59 changes: 59 additions & 0 deletions 59 Chapter8/Interface/Implementing_Interfaces_implement_clause.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package Interface;

// An interface specifies what to do, not how to do.
interface management{

void parenting();
void baby_talks();


}

class parents {

String fatherString;
String motherString;

}

// The general form of a class that includes the implements clause looks like this:
class kids extends parents implements management{

@Override
public void parenting() {
// TODO Auto-generated method stub
System.out.println(fatherString + "'s fatherhood");
}

@Override
public void baby_talks() {
// TODO Auto-generated method stub
System.out.println( motherString + "'s motherese");
}

}


public class Implementing_Interfaces_implement_clause {

public static void main(String[] args) {
// TODO Auto-generated method stub

kids janeKids = new kids();
kids peterKids = new kids();

janeKids.fatherString = "Jansen";
janeKids.motherString = "Sharon";
janeKids.baby_talks();
janeKids.parenting();


peterKids.fatherString = "Bill";
peterKids.motherString = "Laura";
peterKids.baby_talks();
peterKids.parenting();


}

}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.