diff --git a/Chapter11/Creating_a_Thread.java b/Chapter11/Creating_a_Thread.java new file mode 100644 index 0000000..b3c357b --- /dev/null +++ b/Chapter11/Creating_a_Thread.java @@ -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 + + } + +} diff --git a/Chapter8/Interface/Implementing_Interfaces_implement_clause.java b/Chapter8/Interface/Implementing_Interfaces_implement_clause.java new file mode 100644 index 0000000..ec8178e --- /dev/null +++ b/Chapter8/Interface/Implementing_Interfaces_implement_clause.java @@ -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(); + + + } + +}